Professional Documents
Culture Documents
// Create a Scanner
Scanner input = new Scanner(System.in);
if (number % 5 == 0)
System.out.println("HiFive");
if (number % 2 == 0)
System.out.println("HiEven");
if (number % 2 == 1)
System.out.println("HiOdd");
}
}
switch (switch-expression)
{
case value1: statement(s)1; break;
case value2: statement(s)2; break;
...
case valueN: statement(s)N; break;
}
default: statement(s)-for-default;
Example 1 of Switch
import java.util.Scanner;
switch ( score )
{
case 100:
case 99:
case 98:
case 97:
case 96:
case 95:
case 94:
case 93:
case 92:
case 91:
case 90: grade = "A"; break;
case 89:
case 88:
case 87:
case 86:
case 85:
case 84:
case 83:
case 82:
case 81:
case 80: grade = "B"; break;
case 79:
case 78:
case 77:
case 76:
case 75:
case 74:
case 73:
case 72:
case 71:
case 70: grade = "C"; break;
case 69:
case 68:
case 67:
case 66:
case 65:
case 64:
case 63:
case 62:
case 61:
case 60: grade = "D"; break;
H.W
1- Accept 5 marks of a student find the total and average marks. And find the grade
according to the following conditions
else Grade is E
2- Take values of length and breadth of a rectangle from user and check if it is
square or not.
3-Take two int values from user and print greatest among them.
4-A shop will give discount of 10% if the cost of purchased quantity is more
than 1000.
Ask user for quantity
Suppose, one unit will cost 100.
Judge and print total cost for user.
6-Take input of age of 3 people by user and determine oldest and youngest
among them.