Search This Blog

Loading...

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");
        }
    }
}

6 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