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
Microsoft Confirms Windows 11 24H2/25H2 ...
Microsoft has offici...schreckdeividas — 08:52
AntGROUP Inc. / VCap-developer
Ant Download Manager...jasonX — 05:33
Brave 1.88.132 (Chromium 146.0.7680.80)
Release v1.88.132 ...harlan4096 — 17:56
Windows 7 Gets a Modern Makeover in New ...
A new concept vide...harlan4096 — 17:55
Microsoft Releases Emergency Windows 11 ...
Microsoft has rele...harlan4096 — 17:53

[-]
Birthdays
Today's Birthdays
avatar (33)uteluxix
avatar (47)piafcflene
avatar (39)Matthewkah
Upcoming Birthdays
avatar (44)gapedDow
avatar (38)snorydar
avatar (43)Hectorvot
avatar (51)knowhanPluts
avatar (39)Williamengiz
avatar (46)qaqapeti
avatar (44)battsourIonix
avatar (43)CedricSek
avatar (38)Charlesfibre
avatar (38)francisnj3
avatar (43)artmaGoork

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

>