Frontend Development

Java - Simple calculator

Submitted by UBSZZZ, , Thread ID: 196826

Thread Closed
05-02-2021, 05:30 PM
#1
Code:
public static void main(String[] args) {
    // TODO code application logic here
    double o,t,mum;
    Scanner sc=new Scanner(System.in);
    System.out.print("Input number1: ");
    o = sc.nextDouble();
    System.out.print("Input +,-,*,/: ");
    mum = sc.next().charAt(0);
    System.out.print("Input number2: ");
    t = sc.nextDouble();
      if(mum == '+'){
        System.out.println("Sum : "+(o+t));    
      }else if(mum == '-'){
        System.out.println("Sum : "+(o-t));    
      }else if(mum == '*'){
        System.out.println("Sum : "+(o*t));
      }else if(mum == '/'){
        System.out.println("Sum : "+(o/t));
      }
  }

RE: Java - Simple calculator

#2
I am learning java for university, this exercise will help me a lot

RE: Java - Simple calculator

#3
Great share, do you consider that I should learn Java or Python and why? Any clue or comment is appreciated!

RE: Java - Simple calculator

#4
It's the basic of the basic. May help begginers, but I believe there are lots of tutorials already over YouTube for many such things like this.

RE: Java - Simple calculator

#5
as a simple calculator, its code looks good. keep up the work!

RE: Java - Simple calculator

#6
thats java not javascript, wrong forum :kek:
/au4to0][Image: ad0png.png]
[Image: view?username=Venipa&style=small]

RE: Java - Simple calculator

#7
Nice easy program good job

Users browsing this thread: 1 Guest(s)