Search This Blog

Tuesday, December 14, 2010

Menu driven program to accept a number from the user and check * whether it a BUZZ number or to accept any two numbers & print GCD of them - ICSE BOARD QUESTION 2009

/**
 * Write a menu driven program to accept a number from the user and check
 * whether it a BUZZ number or to accept any two numbers & print GCD of them.
 */
import java.io.*;
class questionEIGHT2009
{
    public static void main(String args[]) throws IOException
    {
        int i,j;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("**************MENU*************");
        System.out.println("Type 1 to check if a number is a BUZZ number or not");
        System.out.println("Type 2 to print GCD of any two numbers");
       
        System.out.println("Enter your choice");
        int ch=Integer.parseInt(br.readLine());
       
        switch(ch)
        {
            case 1:
            System.out.println("Enter the number to check if it is buzz number or number");
            int n=Integer.parseInt(br.readLine());
           
            if(n%7==0 || n%10==7)
            {
                System.out.println("The number " +n+ " is a BUZZ number");
            }           
            else
            {
                System.out.println("The number " +n+ " is NOT a BUZZ number");
            }
            break;
           
            case 2:
            System.out.println("Enter any two numbers to print their GCD");
            int n1=Integer.parseInt(br.readLine());
            int n2=Integer.parseInt(br.readLine());
           
            int divisor, dividend;
            if(n1>n2)
            {
                dividend=n1;
                divisor=n2;
            }
            else
            {
                dividend=n2;
                divisor=n1;
            }
           
            int rem=1;
            while(rem!=0)
            {
                rem=dividend%divisor;
                if(rem==0)
                {
                    System.out.println("GCD is = " +divisor);
                }
                else
                {
                    dividend=divisor;
                    divisor=rem;
                }
            }
            break;
           
            default:
            System.out.println("Wrong choice");
        }
    }
}

36 comments:

  1. error: Class names, 'questionEIGHT2009', are only accepted if annotation processing is explicitly requested

    ReplyDelete
  2. Any one can help me with this...Write a Menu driven program to find the area of an Equilateral triangle, an Isosceles triangle and a Scalene triangle as per the user’s choice....

    ReplyDelete
    Replies
    1. Here, theres your answer :)

      import java.io.*;
      public class triangle
      {
      public static void main(String args[]) throws IOException
      {
      InputStreamReader read = new InputStreamReader(System.in);
      BufferedReader in = new BufferedReader(read);
      int c;
      float a,s,p,q,r,b;
      double area;
      System.out.println("1.Area of equilateral triangle");
      System.out.println("2.Area of isosceles triangle");
      c=Integer.parseInt(in.readLine());
      switch(c)
      {
      case 1:
      System.out.println("Enter side of an equilateral triangle");
      s=Float.parseFloat(in.readLine());
      area=Math.sqrt(3*s*s)/4;
      System.out.println("Area="+area);
      break;
      case 2:
      System.out.println("Enter the side and base of isosceles triangle");
      a=Float.parseFloat(in.readLine());
      b=Float.parseFloat(in.readLine());
      area=b/4*(Math.sqrt(4*a*a-b*b));
      System.out.println("Area="+area);
      break;
      default:
      System.out.println("Wrong choice ");
      }
      }
      }



      Delete
  3. hats off to such a basic conceptual program.. although little errors can be pointed out.

    ReplyDelete
  4. Please help me with this
    Write a Menu Driven Program To Accept two numbers and 2 Choices to choose whether the number is a Neon and a Palindrome

    ReplyDelete
  5. its urgent please help to slove this program:
    write a program to print the following pattern:
    1
    31
    531
    7531
    97531
    please solve this problem without buffered reader

    ReplyDelete
    Replies
    1. class Sample
      {
      public void show ()
      {
      int i, j;
      for (i=1;i <=10;i=i+2)
      {
      for (j=i;j>=1;j=j-2)
      System.out.print(j);
      }
      System.out.println ();
      }
      }

      Delete
    2. class Sample
      {
      public void show ()
      {
      int i, j;
      for (i=1;i <=10;i=i+2)
      {
      for (j=i;j>=1;j=j-2)
      System.out.print(j);
      }
      System.out.println ();
      }
      }

      Delete
    3. No I ont want the output as 131531...
      I want it as:
      1
      31
      531
      7531
      97531
      please write it so output comes in as in the gap of 1 line

      Delete
  6. Please ! help me with this program in blue j the simplest way without using buffered reader - ( i'm in 9th standered)

    You want to buy an old car from 'sale and purchase', where you can get a car in depreciated price . The depreciated value of a car is calculated on its showroom price and the number of years it has been used .The depreciated value of a car is calculated as per tariff given below
    no. of yrs used rate of depreciation
    1 10%
    2 20%
    3 30%
    4 50%
    above 4 60%

    Write a menu driven program to input showroom price and the number of years used ('1' for 1yr old, '2' for 2yr old) and so on. Calculate the depreciated value. Display the original price of car , depreciated value and the amount paid for the car.

    ReplyDelete
  7. I want a program to acpt a num. and tell is it armstrong or not without using scanner class or buffred reader . i can only use while do while and for loop......plllzzz HElp..!!

    ReplyDelete
    Replies
    1. You can take input via command line argument s

      Delete
    2. import java.io.*;
      class Armstrong
      {
      public static void main() throws IOException
      {
      BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
      int n,d,r=0,arm=n;
      System.out.println ("enter a no.");
      n=Integer.parseInt (br.readLine ());
      while (n!=0)
      {
      d=n%10;
      r=r+d*d*d*;
      n=n/10;
      }
      if (r==arm)
      {
      System.out.println ("Armstrong no.");
      }
      else
      {
      System.out.println("not an Armstrong no");
      }
      }
      }

      Delete
  8. Hello Anonymous, u can take input via command line arguments

    ReplyDelete
  9. Write a menu driven program in java and check whether it is a neon mumber or not using switch case.?Please tell.

    ReplyDelete
  10. Using the switch statement, write a menu driven program:

    To check and display whether the number input by the user is a composite number or not (A number is said to be a composite, if it has one or more than one factors excluding 1 and the number itself).
    Example: 4, 6, 8, 9, �
    To find the smallest digit of an integer that is input:
    Sample input: 6524
    Sample output: Smallest digit is 2
    Please solve this program without using buffered reader

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Using the switch statement, write a menu driven program:

    To check and display whether the number input by the user is a composite number or not (A number is said to be a composite, if it has one or more than one factors excluding 1 and the number itself).
    Example: 4, 6, 8, 9, �
    To find the smallest digit of an integer that is input:
    Sample input: 6524
    Sample output: Smallest digit is 2
    Please solve this program without using buffered reader

    ReplyDelete
  13. Using the switch statement, write a menu driven program:

    To check and display whether the number input by the user is a composite number or not (A number is said to be a composite, if it has one or more than one factors excluding 1 and the number itself).
    Example: 4, 6, 8, 9, �
    To find the smallest digit of an integer that is input:
    Sample input: 6524
    Sample output: Smallest digit is 2
    Please solve this program without using buffered reader

    ReplyDelete
  14. Wap to accept a number and check if it is a buzz number or not without using modulous operator.

    ReplyDelete
  15. please help me.Write a Menu driven for all mathematical sums





    ReplyDelete
  16. please help me.Write a Menu driven for all mathematical sums





    ReplyDelete
    Replies
    1. Its very difficult to understand the purpose of every line...can sm1 make me understand...

      Delete
  17. Can anyone solve this pattern?
    97531
    7531
    531
    31
    1

    ReplyDelete
  18. Can anyone solve this pattern?
    97531
    7531
    531
    31
    1

    ReplyDelete
    Replies
    1. int i,j;
      for(int i=9;i>=1;i-=2)
      {
      for(int i=j;j>=1;j-=2)
      {
      System.out.println(j+" ")
      {
      System.out.println(j);
      }

      Delete
    2. import java.util.*;

      public class Main
      {
      public static void main(String[] args)
      {
      /*97531
      7531
      531
      31
      1
      */
      int s=9,m=9;
      for (int i=1;i<=5;i++)
      {
      s=m;
      for(int j=5;j>=i;j--)
      {

      System.out.print(s+" ");
      s=s-2;
      }
      System.out.println();
      }
      }
      }

      Delete
  19. Can any one plzzz give me 20 programs for class 10

    ReplyDelete
  20. Jai Shri ram
    Jai Shri ram
    Jai Shri ram
    Jai. Shri ram














    ReplyDelete
    Replies
    1. use scanner class not buffered reader

      Delete
  21. Can anyone help me in writing a program of menu driven the problem is like this write a menu driven java program which will read the number and implement the following methods using command line argument and methods are 1.Find factorial 2. Test armstrong 3. Test palindrome

    ReplyDelete
  22. can someone plzz help me Write a menu-driven class to accept a number from the user and check whether it is anArmstrong numberor aNivennumber.a) A number is said to be an Armstrong number if it is equal to the sum of the cubes of its digits. For example: 153= 13+ 53+ 33=153.b) Any positive integer which is divisible by the sum of its digits is a Harshad Number or Niven Number.Ex: Niven numbers:102(sum of digits is 3 and 102 is divisible by 3)152(sum of digits is 8 and 152 is divisible by 8)Not Niven:16(sum of digits is 7 and 16 is not divisible by 7) its urgent

    ReplyDelete