Geeks for your information
Java: a simple calculator! - Printable Version

+- Geeks for your information (https://www.geeks.fyi)
+-- Forum: Programing/Development (https://www.geeks.fyi/forumdisplay.php?fid=52)
+--- Forum: Java (https://www.geeks.fyi/forumdisplay.php?fid=56)
+--- Thread: Java: a simple calculator! (/showthread.php?tid=4949)



Java: a simple calculator! - Deep900 - 30 December 18

Hi guys, here is a very simple method to write a calculator in Java:

Code:
public static void main(String[] args){

System.out.println("for the sum press a, for the multiplication press b, for the division press c, for the sub press d");

Scanner read = new Scanner(System.in);

String s = read.nextLine();

if(s.equals("a"))
{
sum(3,3);
}
else if(s.equals("b"))
{
mul(3,3);
}
else if(s.equals("c"))
{
div(6,2);
}
else if(s.equals("d"))
{
sub(9,5);
}

public void sum(one,two)
{
System.out.println(one+two);
}

public void mul(one,two)
{
System.out.println(one*two);
}

public void sub(one,two)
{
System.out.println(one-two);
}

public void div(one,two)
{
System.out.println(one/two);
}
}