Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » I need help making a calculator in java(I am a beginner in java programming and i currently am making a calculator in java. i use eclipse.)
icon5.gif  I need help making a calculator in java [message #1070438] Thu, 18 July 2013 01:00 Go to next message
Xavier Lacasse is currently offline Xavier LacasseFriend
Messages: 1
Registered: July 2013
Junior Member
hi, i am trying to use the Scanner tool to scan these symbols : *, /, -, +

my code:

this is the part that is used for integers:

import java.util.Scanner;
class CalculatorInt {
public static void main(String args[]) {
int FirstNumber;
double Sign;
int SecondNumber;
Scanner myScanner = new Scanner(System.in);
FirstNumber = myScanner.nextInt();
Sign = myScanner.next {
if (Sign = *) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = /) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = -) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = +) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}
}
}
}
}
}
}
}
}
}



this is the part used for numbers with decimals:

import java.util.Scanner;
class CalculatorInt {
public static void main(String args[]) {
double FirstNumber;
double Sign;
double SecondNumber;
Scanner myScanner = new Scanner(System.in);
FirstNumber = myScanner.nextInt();
Sign = myScanner.next {
if (Sign = *) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = /) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = -) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = +) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}
}
}
}
}
}
}
}
}
}
the 2 file attachments are the java code in java. the CalculatorInt.class is for the integers and the CalculatorDouble.class is for the numbers with decimals. Please tell me how to fix my code to make the scan work.
Re: I need help making a calculator in java [message #1070656 is a reply to message #1070438] Thu, 18 July 2013 12:05 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Two comments: don't post compiled class files and expect people to run them on their machines.

Second: use the compiler's error messages to detect the errors in your program and fix them before wondering why the code doesn't work.
Re: I need help making a calculator in java [message #1752113 is a reply to message #1070438] Thu, 19 January 2017 01:07 Go to previous message
Emily Wood is currently offline Emily WoodFriend
Messages: 1
Registered: January 2017
Junior Member
this is how to make a calculator:

package temporaryCaluclator;

import java.util.Scanner;

public class Calculator1000 {
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.println("Enter Equasion Here:");
while (true) {
int value = input.nextInt();
String text = input.next();
switch (text) {
case "+":
int value2 = input.nextInt();
int add = value + value2;
System.out.println(add);
break;
case "-":
value2 = input.nextInt();
add = value - value2;
System.out.println(add);
break;
}

}
}
}

paste this into eclipse and you will have a simple calculator! but remember to rename your class and package to the name of your own ones
Previous Topic:Is there any way to create xml by commands?
Next Topic:Annotation Processors in Neon (4.6.0) and Maven
Goto Forum:
  


Current Time: Thu Oct 03 23:37:12 GMT 2024

Powered by FUDForum. Page generated in 0.03058 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top