I'm a bit of a noob at Java (just started learning the language) but C# and Java have many similarities, and was able to cook this up:
Code
package test;
import java.util.Scanner;
public class start {
static Scanner input = new Scanner(System.in);
//static String calc = input.next();
static int equas=1;
static Boolean loop = true;
static Boolean errorLoop = true;
public static void main(String[] args){
while(loop){
//System.out.print("\f");
errorLoop = true; //reset the value
String calc = input.next();
if(calc.contains("*"))equas = 1;
else if(calc.contains("/")) equas = 2;
else if(calc.contains("+")) equas = 3;
else if(calc.contains("-")) equas = 4;
try{
if(equas==1){
String[] numbers = calc.split("\\*");
int a = Integer.parseInt(numbers[0]);
a *= Integer.parseInt(numbers[1]);
System.out.print(numbers[0] + " x " + numbers[1] + " = " + a + "\n");
}
else if(equas==2){
String[] numbers = calc.split("/");
int a = Integer.parseInt(numbers[0]);
a /= Integer.parseInt(numbers[1]);
System.out.print(numbers[0] + " ÷ " + numbers[1] + " = " + a + "\n");
}
else if(equas==3){
String[] numbers = calc.split("\\+");
int a = Integer.parseInt(numbers[0]);
a += Integer.parseInt(numbers[1]);
System.out.print(numbers[0] + " + " + numbers[1] + " = " + a + "\n");
}
else if(equas==4){
String[] numbers = calc.split("-");
int a = Integer.parseInt(numbers[0]);
a -= Integer.parseInt(numbers[1]);
System.out.print(numbers[0] + " - " + numbers[1] + " = " + a + "\n");
}
}
catch(Exception E){
if(errorLoop){ //bug fix
System.out.print("Error on syntax. You typed the equasion wrong, ex... 5+5, 5*5");
errorLoop = false;
}
}
}
}
}
Basically, just type 5*5, 5+5, 5/5 etc...
My mistake was using integer data types instead of double.