Go to Top

Wednesday 2 November 2011

Utilities 20 : Old style calculator

This is a kind of an old style calculator. You have to enter a number then enter the sign then the number and so on. This isn't one of my best programs, but it doesn't pay to hide it.

Java Program :

import java.io.*;
class calculator_working_edition
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     double a,b=0;
     String q;
     char o='a',opt='b';
     System.out.println("\t\t*****Calculator*****\n");
     System.out.print("Enter the number : ");
     a=Double.parseDouble(br.readLine());
     System.out.print("\n");
     loop1:while(opt!='Y')
     {
         System.out.print("Enter option : ");
         q=br.readLine();
         o=q.charAt(0);
         if(o=='=')
         break loop1;
         if(o!='!')
         {
            System.out.print("\nEnter the number : ");
            b=Double.parseDouble(br.readLine());
        }
         switch(o)
         {
             case '+':
             a=a+b;
             break;
             case '-':
             a=a-b;
             break;
             case '/':
             a=a/b;
             break;
             case '*':
             a=a*b;
             break;
             case '!':
             a=Math.sqrt(a);
             break;
             default:
             System.out.println("\nInvalid input");
            }
         System.out.print("\n");
        }
        System.out.println("\nThe result is : "+a+"\n");
        System.out.println("Thank you for using this short program");
    }
}
           
I will be working on a new calculator this time. So keep on a lookout for that one.

No comments:

Post a Comment

ShareThis