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:
[-]
Welcome
You have to register before you can post on our site.

Username/Email:


Password:





[-]
Recent Posts
Google Chrome 149.0.7827.200/201
Google Chrome 149....harlan4096 — 08:26
Brave 1.91.180 (Jun 26, 2026)
Release Notes v1.9...harlan4096 — 08:24
Adobe Acrobat Reader DC 2026.001.21691
Adobe Acrobat Read...harlan4096 — 08:22
PowerToys v0.100.2
Release v0.100.2 ...harlan4096 — 08:21
GeForce Game Ready Driver 452.06
NVIDIA 580.173.02 Li...harlan4096 — 08:18

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

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

>