Dismiss this notice
Panda Dome Complete MakeUSLaugh Mother's Day 2019 Giveaway - https://www.geeks.fyi/showthread.php?tid=6837

Dismiss this notice
Iobit Driver Booster 6 Professional Mother's Day 2019 Giveaway - https://www.geeks.fyi/showthread.php?tid=6777

Dismiss this notice
Advanced SystemCare 12 Professional Mother's Day 2019 Giveaway - https://www.geeks.fyi/showthread.php?tid=6776


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: 1 Guest(s)
[-]
Latest Threads
Apple Announces World's First 8-Core Mac...
Last Post: silversurfer
Yesterday 20:35
» Replies: 0
» Views: 33
Microsoft Redesigns Outlook Notification...
Last Post: silversurfer
Yesterday 20:33
» Replies: 0
» Views: 39
Chromium-Based Microsoft Edge Preview fo...
Last Post: silversurfer
Yesterday 20:29
» Replies: 0
» Views: 30
Mozilla Firefox 67 Now Available for Dow...
Last Post: silversurfer
Yesterday 20:27
» Replies: 0
» Views: 26
Linux Kernel Privilege Escalation Vulner...
Last Post: silversurfer
20 May 19 16:51
» Replies: 0
» Views: 38
User Data Exposed in Stack Overflow Hack
Last Post: silversurfer
20 May 19 16:47
» Replies: 0
» Views: 33
TeamViewer Confirms It Was Hacked in 201...
Last Post: silversurfer
20 May 19 16:45
» Replies: 0
» Views: 36
Samsung Galaxy S11 Codenamed Revealed
Last Post: silversurfer
20 May 19 15:47
» Replies: 0
» Views: 41
Mozilla Firefox 67 to Kick Off WebRender...
Last Post: silversurfer
20 May 19 15:43
» Replies: 0
» Views: 56
Avast Blog_Security News: Closing the cy...
Last Post: JM Safe
20 May 19 10:22
» Replies: 1
» Views: 43
Microsoft recommended block rules
Last Post: JM Safe
20 May 19 10:17
» Replies: 1
» Views: 59
Evaluating threat intelligence sources
Last Post: JM Safe
20 May 19 09:35
» Replies: 1
» Views: 38
MRG Effitas: Online Banking / Browser Se...
Last Post: harlan4096
20 May 19 07:31
» Replies: 0
» Views: 63
Avast Blog_Security News: Avast discusse...
Last Post: harlan4096
20 May 19 07:10
» Replies: 0
» Views: 35
THE TRADE SECRET: Firms That Promised Hi...
Last Post: harlan4096
20 May 19 07:02
» Replies: 0
» Views: 38
Google To Suspend Some Business With Hua...
Last Post: harlan4096
20 May 19 06:59
» Replies: 0
» Views: 35
Sony's Flagship Xperia 1 21:9 Smartphone...
Last Post: harlan4096
20 May 19 06:58
» Replies: 0
» Views: 39
AMD Reiterates 7nm Roadmap: Navi, Matiss...
Last Post: harlan4096
20 May 19 06:56
» Replies: 0
» Views: 30
Fix Windows 10 can't be restored after y...
Last Post: harlan4096
20 May 19 06:53
» Replies: 0
» Views: 32
Gmail tracks all your purchases, it is d...
Last Post: harlan4096
20 May 19 06:50
» Replies: 0
» Views: 28

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