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