Presentation is loading. Please wait.

Presentation is loading. Please wait.

2012.10.19. Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.

Similar presentations


Presentation on theme: "2012.10.19. Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice."— Presentation transcript:

1 2012.10.19

2 Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice

3 import java.io.* ; public class InputStr{ public static void main(String[] args) throws java.io.IOException { BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in)); // keyin String str = keyin.readline(); // keyin System.out.println(str); }

4 import java.util.Scanner; public class scan { public static void main(String[] args) throws Exception{ Scanner keyin = new Scanner(System.in); String str = keyin.nextLine(); System.out.print(str); }

5 if(num%2==0){ System.out.println(Even number); } else{ System.out.println(Old number); };

6 if(num%2==0){ System.out.println(Even number!!); System.out.println(num = +num); } else { System.out.println(Old number!!); System.out.println (num = +num); }

7 Error 1: if ( radius >= 0 ) area = radius * radius * 3.14; System.out.println(The area is + area);

8 if ( radius >= 0 ) { area = radius * radius * 3.14; System.out.println(The area is + area); }

9 Error 2: if ( radius >= 0 ); { area = radius * radius * 3.14; System.out.println(The area is + area); }

10 if ( radius >= 0 ); { area = radius * radius * 3.14; System.out.println(The area is + area); }

11 Error 3: if ( a = true ) { System.out.println(a is true !! ); }

12 if ( a == true ) { System.out.println(a is true !! ); }

13 OperatorNameDescription !notlogical negation &&andlogical conjunction ||orlogical disjunction ^exclusive orlogical exclusive

14

15 num = 1 num = 2 else Statement 1 Statement else Statement 2 true false

16 switch (num) { case 1:statement 1; break; case 2:statement 2; break; default:statement else; System.exit(0); }

17 import java.io.*; public class Season2Wear { public static void main(String[] argv) throws IOException { System.out.println(" 1. 2. 3. 4. "); System.out.print(" "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); int season = Integer.parseInt(str); switch (season) { case 1: // season 1 System.out.println(" "); break; // case case 2: // season 2 System.out.println(" "); break; // case case 3: // season 3 System.out.println(" "); break; // case case 4: // season 4 System.out.println(" "); break; // case }

18 import java.util.Scanner; public class SubtractionQuiz{ public static void main(String[] args){ int number1=(int)(Math.random()*10); int number2=(int)(Math.random()*10); if(number1<number2){ int temp =number1; number1=number2; number2=temp; System.out.print("What is "+number1+" - "+number2+" ? "); Scanner input new Scanner(System.in); int answer =input.nextInt(); if(number1-number2==answer){ System.out.println("You are correct!!"); }else{ System.out.println("Your answer is wrong\n"+number1+"-"+number2+"is"+(number1- number2)); }

19 1., 2. 90~100 A; 80~89 B; 70~79 C; 60~69 D;0~60 E( ) ( switch)

20 3.Write a program that prompts the user to enter a,b,c,d,e and f and displays the result. If ad-bc is 0,report that The equation has no solution. 4.Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank(Ace,2,3,4,5,6,7,8,9,10,Jack,Queen,King) and suit(Clubs,Diamonds,Hearts,Spades) of the card.

21 Ppt http://oss.csie.fju.edu.tw/~jastine01/ppt.html


Download ppt "2012.10.19. Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice."

Similar presentations


Ads by Google