Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.
Showing posts with label switch statements. Show all posts
Showing posts with label switch statements. Show all posts

Thursday, March 29, 2012

WAP of Switch case in Java

/*WAP to capture the two integer values from user and perform following actions according to user Requierement
1. Addition
2. Substraction
3. Multiplication
4. Division
5. Exit
*/
import java.lang.*;
import java.io.*;
class oprations
{
 public void InputMsg()
 {System.out.println("Enter Two Integer numbers. ");}
 
 public void continueMsg()
 {System.out.println("Do you want to Continue. \n1. Yes \n0. No");}
 
 public static void main (String args[]) throws IOException
 {
  int a , b, choice = -1 ;
  
  do
  {
    System.out.println("Choose a Opration");
    System.out.println("1. Addition \n2. Substraction \n3. Multiplication \n4. Division \n5. Exit \nYour Choice: ");

    BufferedReader br = new BufferedReader(new 
         InputStreamReader(System.in));
    oprations e = new oprations();
    choice = Integer.parseInt(br.readLine());
    int repeate = -1;
    
   do
   {
    
    switch(choice)
    {
     
     case 1: e.InputMsg();
        a = Integer.parseInt(br.readLine());
        b = Integer.parseInt(br.readLine());
     System.out.println("Addition = "+(a+b));
    
     e.continueMsg();
     repeate = Integer.parseInt(br.readLine());
     break;
     case 2: e.InputMsg();
        a = Integer.parseInt(br.readLine());
        b = Integer.parseInt(br.readLine());
     System.out.println("Substraction = "+(a-b));
     
     e.continueMsg();
     repeate = Integer.parseInt(br.readLine());
     break;
     case 3: e.InputMsg();
        a = Integer.parseInt(br.readLine());
        b = Integer.parseInt(br.readLine());
     System.out.println("Multiplication = "+(a*b));
     
     e.continueMsg();
     repeate = Integer.parseInt(br.readLine());
     break;
     case 4: e.InputMsg();
        a = Integer.parseInt(br.readLine());
        b = Integer.parseInt(br.readLine());
     System.out.println("Division = "+(a/b));
     
     e.continueMsg();
     repeate = Integer.parseInt(br.readLine());
     break;
     case 5: System.out.println("BYE!"); 
     break;
     default: System.out.println("Invalid Input.");
    }
    
   }while(repeate != 0 && choice != 5);
   
  }while(choice != 5); 
 }
 
}

Friday, September 24, 2010

WAP to An improved version of the season program


/*WAP to An improved version of the season program*/
class Switch {
public static void main(String args[]) {
int month = 4;
String season;
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
break;
case 3:
case 4:
case 5:
season = "Spring";
break;
case 6:
case 7:
case 8:
season = "Summer";
break;
case 9:
case 10:
case 11:
season = "Autumn";
break;
default:
season = "Bogus Month";
}
System.out.println("April is in the " + season + ".");
}
}

WAP to check that In a switch, break statements are optional


/*WAP to check that In a switch, break statements are optional*/
class MissingBreak {
public static void main(String args[]) {
for(int i=0; i<12; i++)
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");
}
}
}

Tuesday, September 21, 2010

WAP to Demonstrate switch statements


/*WAP to Demonstrate switch statements*/
class SampleSwitch {
public static void main(String args[]) {
for(int i=0; i<6; i++)
switch(i) {
case 0:
System.out.println("i is zero.");
break;
case 1:
System.out.println("i is one.");
break;
case 2:
System.out.println("i is two.");
break;
case 3:
System.out.println("i is three.");
break;
default:
System.out.println("i is greater than 3.");
}
}
}

ADS

How to earn online

How to earn online:
Step - 1 :
signup for PayPal, to recieve your online earning
click here:
https://www.paypal.com/in/mrb/pal=CZ7224TZBMCBL
step - 2 : Singup these 4 sites & earn & enjoy! Read site to know how to earn.
1. trekpay
Earn up to $0.02 (2 cents) per click.
http://www.trekpay.com/?ref=34690
2. neobux
Earn up to $0.02 (2 cents) per click.
Click here:
http://www.neobux.com/?r=Moneyearner786

AddMe

Bookmark and Share