Sunday, 5 November 2017

java program mutliple case for 1 statement



Problem 15:
Write a program that take number from user and check number is less then five 0r lessthen 10 simply using switch statement
Discripition:
Case 1 2 3 4 for less then five and 5 6 7 8 9 less then ten
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
 
 Scanner input = new Scanner(System.in);

 System.out.print("Enter the number: ");
 int i= input.nextInt();

switch(i) {
case 0:
case 1:
case 2:
case 3:
case 4:
System.out.println("i is less than 5");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println("i is less than 10");
break;
default:
System.out.println("i is 10 or more");}
 }
 }
Output:
               


java simple bill project



Problem 14:
Write a program that calculate the bill if unit less then 100; one unit price is 10Rs if greater then 100 but less then 200; one unit price is 13Rs if greater the 200 less then 300;  One unit price is 17Rs If greater then 300 unit price is 20;
Discripition:
Simply multiply units with suitable prices.
Solution:

public class Message {
 public static void main(String[] args) {
 
 Scanner input = new Scanner(System.in);

 System.out.print("Enter the total units: ");
 int totalBill, unit = input.nextInt();

if(unit<=100)
    totalBill=unit*10;
else if(unit>100&&unit<200)
    totalBill=unit*13;
else if(unit>200&&unit<300)
    totalBill=unit*17;
else
    totalBill=unit*20;
 System.out.println("Your total bill is "+totalBill);
 }
 }
Output:
     


java program that check days of week



Problem 13:
Write a program that check days of weak
Descriptions:
Using switch statement
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
 
 Scanner input = new Scanner(System.in);

 System.out.print("Enter number of day: ");
 int year = input.nextInt();

 switch (year % 12) {
 case 0: System.out.println("Monday"); break;
 case 1: System.out.println("Tuesday"); break;
 case 2: System.out.println("Wednesday"); break;
 case 3: System.out.println("Thursday"); break;
 case 4: System.out.println("Friday"); break;
 case 5: System.out.println("Saturday"); break;
 case 6: System.out.println("Sunday");
 default:
     System.out.println("Wrong entery");
 }
 }
Output:

java program that check Chines year



Problem 12:
Write a program that check Chines year
Discripition:
By using switch statement
Solution:
import java.util.*;
public class Message {
 public static void main(String[] args) {
 
 Scanner input = new Scanner(System.in);

 System.out.print("Enter a year: ");
 int year = input.nextInt();

 switch (year % 12) {
 case 0: System.out.println("monkey"); break;
 case 1: System.out.println("rooster"); break;
 case 2: System.out.println("dog"); break;
 case 3: System.out.println("pig"); break;
 case 4: System.out.println("rat"); break;
 case 5: System.out.println("ox"); break;
 case 6: System.out.println("tiger"); break;
 case 7: System.out.println("rabbit"); break;
 case 8: System.out.println("dragon"); break;
 case 9: System.out.println("snake"); break;
 case 10: System.out.println("horse"); break;
 case 11: System.out.println("sheep");
 }
 }
 }
Output:

javaprogram that check first number is multiple of second number.



Problem 11:
Write a program that check first number is multiple of second number.
Discripition:
Using remainder operator
Solution:

import java.util.*;
public class Message {
 public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
   System.out.println("Enter the frist number");
    int num=input.nextInt();
   System.out.println("Enter the second number");
    int num1=input.nextInt();
    if(num%num1==0)
    System.out.println("This is multiple");
    else
        System.out.println("This is not multiple ");
 }}
Output: