Deitel-ch3

Example3_13

posted Feb 1, 2014, 8:07 AM by dldar masud   [ updated Feb 1, 2014, 8:08 AM by Karwan Jacksi ]

import java.util.*;
public class Example3_13 {
static Scanner in = new Scanner(System.in);
  public static void main(String[] args) 
  {
        boolean done = true;
        int lampWatt, price;
        while(done)
        {
           System.out.print("Enter the  lamp watt:");
           lampWatt = in.nextInt();
           switch(lampWatt)
           {
              case 40:
                    price = 1000;
                    System.out.println("Watt = " + lampWatt + " Price = " + price);
                    break;
              case 60:
                    price = 1200;
                    System.out.println("Watt = " + lampWatt + " Price = " + price);
                    break;
              case 75:
                    price = 1500;
                    System.out.println("Watt = " + lampWatt + " Price = " + price);
                    break;
              case 100:
              case 150:
                    price = 1800;
                    System.out.println("Watt = " + lampWatt + " Price = " + price);
                    break;
              case 200:
                    price = 2500;
                    System.out.println("Watt = " + lampWatt + " Price = " + price);
                    break;
              default:
                    System.out.println("The value of watt is illegal.");
                    done = false;
           }//end of switch
    }//end of while

  }

}

Example3_12

posted Feb 1, 2014, 8:01 AM by dldar masud   [ updated Feb 1, 2014, 8:05 AM by Karwan Jacksi ]




import java.util.*;
public class Example3_12 {
static Scanner in = new Scanner(System.in);
  public static void main(String[] args) 
  {
  
                int num, count1 = 0, count2 = 0;
    
     while(true)
     {
        
                 System.out.print("Enter an int number:");
        num = in.nextInt();
        
                  if (num == 0)
           break;
      
                  if(num % 2 == 0)
           count1 ++;
        
              else
           count2 ++;
      }
      System.out.println("Even = " + count1 + ", Odd = " + count2);
  }

}

Example3_6

posted Feb 1, 2014, 7:58 AM by dldar masud   [ updated Feb 1, 2014, 8:05 AM by Karwan Jacksi ]



import java.util.*;

public class Example3_6 {
  
     static Scanner in = new Scanner(System.in); 
         public static void main(String[] args){
int x, i = 0, sum = 0;
System.out.print("Enter an integer number : ");
x = in.nextInt();
  while(x != 0)
   {
sum += x * x;
System.out.print("Enter an integer number : ");
x = in.nextInt();
}
System.out.println("Sum of square is : " + sum);
System.out.println("Number of numbers is : " + i);
}
}



1-3 of 3