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

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:

2012.10.19

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

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); }

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); }

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

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); }

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

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

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

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

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

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

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

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

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

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 }

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 { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/5/1503882/slides/slide_18.jpg", "name": "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

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

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.

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