Wednesday, October 14, 2015

How to Write Simple Calculator in Java Programming Language + video tutorial

How to Write Simple Calculator in Java Programming Language

The following source code is a simple calculator program in the Java language.

class SimpleCalculator{
  public static void main(String args[]){
   int x, y, result;
   char op;
   Scanner in = new Scanner(System.in);

   System.out.println("Enter x : "); x = in.nextInt();
   System.out.println("Enter y : "); y = in.nextInt();
   System.out.println("Write Operator (+ or - or / or *) : "); op = in.nextLine();

   if (op == '+'){ result = x + y; }
   if (op == '-'){ result = x - y; }
   if (op == '*'){ result = x * y; }
   if (op == '/'){ result = x / y; }

  System.out.println("x "+ op +" y = "+ result);
 }
}

you can see the output in this simple tutorial video:


ShadowOfBdg© - All rights reserved. 

No comments:

Post a Comment