Dismiss this notice
Avast Premier Photo Caption - [Only registered and activated users can see links Click here to register]

Dismiss this notice
FastestVPN Accounts Giveaway - [Only registered and activated users can see links Click here to register]


Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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 Like JM Safe's post:
  • Der.Reisende, harlan4096, silversurfer
Reply


Messages In This Thread
Java: a simple calculator! - by JM Safe - 30 December 18, 20:33

Forum Jump:


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

Username:


Password:





[-]
Recent Posts
RogueKiller V13.4.4
V13.4.4 09/16/2019...harlan4096 — 12:50
Avast Blog_Security News: U.S. sanctions...
Can threats to ...harlan4096 — 07:44
Avast Blog_Security News: DDoS attack fo...
Plus, a BEC bus...harlan4096 — 07:41
How Deepfakes Can Ruin Your Business
And How You Can...harlan4096 — 07:33
64-Core AMD EPYC Rome Achieves World's F...
On Friday, Beam...harlan4096 — 07:26

[-]
Birthdays
Today's Birthdays
avatar (42)rarinsWax
Upcoming Birthdays
avatar (32)fapedDow
avatar (42)pohudidere
avatar (32)eqiduseb
avatar (39)ThomasLYDAY
avatar (34)upakoExapy
avatar (43)skepwHug
avatar (32)RicardoGoase
avatar (37)Denpokhew
avatar (29)azidony
avatar (34)maskbSleew

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

>