System.out.println("Enter the area code: "; areacode = keyboard.nextInt(); if (areacode == 732 || areacode == 973 || areacode == 908) System.out.println("Local call"); else System.out.println("Long distance");
System.out.println("Enter the area code: "; areacode = keyboard.nextInt(); if (areacode == 732 || areacode == 848) System.out.println("Local"); else if (areacode == 201 || areacode == 908 || areacode == 973) System.out.println( "North Jersey"); else if (areacode == 609) System.out.println("South Jersey"); else System.out.println("Not in Jersey");
System.out.println("Enter a character: "); str = keyboard.next(); ch = str.charAt(0); if (ch >= 'A' && ch <= 'Z') System.out.println(ch + " is an uppercase letter"); else if (ch >= 'a' && ch <= 'z') System.out.println(ch + " is a lowercase letter"); else if (ch >= '0' && ch <= '9') System.out.println(ch + " is a digit"); else System.out.println(ch + " is a special character");
System.out.print("Enter the speed limit: "); speedLimit = keyboard.nextInt();; System.out.print("Enter the actual speed: "); actualSpeed = keyboard.nextInt(); overlimit = actualSpeed - speedLimit; if (overlimit >= 1 && overlimit <=14) fine = 75; else if (overlimit <=24) fine = 125; else fine = 215; System.out.println("The fine for travelling " + overlimit + "miles over the speed limit is " + fine);
1 3
2 3
1 3
10 10
3 7 6 z
The value of x is 3
if (age < 18) System.out.println("Under age"); else if (age < 65) System.out.println("Regular voter"); else System.out.println("Senior voter");
if (a > 0) if (a < 20) { System.out.println("A is in range"); b = 5; } else { System.out.println("A is too large"); b = 3; } else System.out.println("A is too small"); System.out.println("All done");
System.out.print("Enter a number: "); num = keyboard.nextInt(); switch (num % 2) { case 0: System.out.println("even"); break; case 1: System.out.println("odd"); break; }
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2013