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 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
Malwarebytes 5.1.3.110
Malwarebytes 5.1.3...Mohammad.Poorya — 00:51
Music Videos
Billy Joel - The Riv...jAcos — 17:24
Movies! Movies!
Beverly Hills Cop: A...jAcos — 17:22
TV Series
Matlock Kathy Bat...jAcos — 17:16
F-Secure 19.4
What's new in the ...harlan4096 — 09:44

[-]
Birthdays
Today's Birthdays
avatar (42)techlignub
avatar (41)Stevenmam
avatar (48)onlinbah
Upcoming Birthdays
avatar (43)wapedDow
avatar (49)steakelask
avatar (43)Termoplenka
avatar (41)bycoPaist
avatar (47)pieloKat
avatar (41)ilyagNeexy
avatar (49)donitascene
avatar (49)Toligo

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

>