Java: a simple calculator!
#1
Lightbulb 
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);
}
}
[-] The following 3 users say Thank You to Deep900 for this post:
  • Der.Reisende, harlan4096, silversurfer
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
[-]
Welcome
You have to register before you can post on our site.

Username/Email:


Password:





[-]
Recent Posts
KeyScrambler 3.19.0.2
KeyScrambler 3.19....harlan4096 — 13:05
AdGuard for Windows 7.22.3
AdGuard for Window...harlan4096 — 13:04
VMware Workstation Pro 25H2u1
VMware Workstation...harlan4096 — 13:02
Opera 128
Hello! We’re ha...harlan4096 — 12:59
NanaZip 6.0 Update 1 (6.0.1638.0)
NanaZip 6.0 Update...harlan4096 — 12:57

[-]
Birthdays
Today's Birthdays
No birthdays today.
Upcoming Birthdays
No upcoming birthdays.

[-]
Online Staff
There are no staff members currently online.

>