Dismiss this notice
WinRAR forever! Father's Day 2019 Giveaway - [Only registered and activated users can see links Click here to register]

Dismiss this notice
SSDkeeper™ Professional Father's Day 2019 Giveaway - [Only registered and activated users can see links Click here to register]

Dismiss this notice
Ashampoo Cinemagraph Father's Day 2019 Giveaway - [Only registered and activated users can see links Click here to register]

Dismiss this notice
Revo Uninstaller Pro 4 Father's Day 2019 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


Forum Jump:


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

Username:


Password:





[-]
Recent Posts
Skype 8.48.0.51
Skype 8.48.0.51: ...harlan4096 — 15:59
Google Allows G Suite Users to Log In Wi...
Google on Tuesday an...silversurfer — 15:08
EA Games Login Flaw Exposed Accounts of ...
Researchers have dis...silversurfer — 15:03
Windows 10 Bug Makes the Shutdown Proces...
A bug in Windows 10 ...silversurfer — 12:17
[Giveaway] MOVIEJACK
MOVIEJACK 4.0.7026 ...ismail — 12:15

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

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

>