package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[])throws Exception{
 int num , choice;
 BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
 boolean doit= true ;
 while (doit){
 System.out.println("請輸入數值");
 num=Integer.parseInt(br.readLine());
 if(num%2==0)
  System.out.println(num+"為偶數");
 else
  System.out.println(num+"為奇數");
 System.out.print("是否繼續執行? 繼續請輸入1  欲結束則輸入2");
 choice = Integer.parseInt(br.readLine());  
 if(choice==2) {doit=false;
 System.out.println("程式結束執行");
 }
 }
 }
}

 

---

package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[]) throws Exception {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 int num, choice;
 boolean doit = true;
 while (doit) {//當doit成立時,要一直做
  System.out.println("請輸入數值");
  num = Integer.parseInt(br.readLine());
 if (num % 2 == 0)
  System.out.println(num + "為偶數");

 else
  System.out.println(num + "為奇數");
  System.out.print("是否繼續執行? 繼續請輸入1  欲結束請輸入2");
  choice = Integer.parseInt(br.readLine());
 if (choice == 2) {doit = false;
  System.out.println("程式結束執行"); // 程式區塊
   }
  }
 }
}

 

---

 

package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[]) throws Exception {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 int num, choice;
 String pointer="y",b="y";
 while (pointer.equals(b)) {//字串物件 值的比較
  System.out.println("請輸入數值");
  num = Integer.parseInt(br.readLine());
 if (num % 2 == 0){
  System.out.println(num + "為偶數");}
 else{
  System.out.println(num + "為奇數");}
  System.out.print("是否繼續執行? 繼續請輸入1  欲結束請輸入2");
  choice = Integer.parseInt(br.readLine());
  pointer=br.readLine(); 
  System.out.println("pointer="+pointer);
 } // while結束
  System.out.println("程式結束執行"); // 程式區塊
 }// main結束執行
} //class結束

 ---

package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[]) throws Exception {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  int num, choice = 1;

while (choice==1) { //字串物件 值的比較
  System.out.println("請輸入數值");
  num = Integer.parseInt(br.readLine());
 if (num % 2 == 0){
  System.out.println(num + "為偶數");}
 else{
  System.out.println(num + "為奇數");}
  System.out.print("是否繼續執行? 繼續請輸入1  欲結束請輸入2");
  choice = Integer.parseInt(br.readLine());
  System.out.println("choice="+choice);
 } // while結束
  System.out.println("程式結束執行"); // 程式區塊
 }// main結束執行
} //class結束


--- 

package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[]) throws Exception {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 int a,b;
  System.out.println("請輸入第一個數值");
  a = Integer.parseInt(br.readLine());
  System.out.println("請輸入第二個數值");
  b = Integer.parseInt(br.readLine());
 if (a==b)
  System.out.println("a = b");
 else if (a>b)
 System.out.println(a+">"+b);
 
 else
  System.out.println(a+"<"+b);
 }
}


 ---

 

package chap5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class t1030 {
 public static void main(String args[]) throws Exception {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 int proscore;
 boolean doit = true;
 while (doit){

  System.out.println("請輸入數值");
  proscore = Integer.parseInt(br.readLine());
 if (proscore >= 80)
  System.out.println("甲");
 if (proscore >= 60)
  System.out.println("乙");

 if (proscore < 60)
  System.out.println("丙");
   }
  }
 }

 

 

 

 

 

 

 

 

 

arrow
arrow
    全站熱搜

    玥君 發表在 痞客邦 留言(0) 人氣()