Попросите только вставить числаJAVA

Программисты JAVA общаются здесь
Anonymous
Попросите только вставить числа

Сообщение Anonymous »

Итак, я пытаюсь сделать простой калькулятор. даст мне ошибку. < /p>

Как я делаю это в порядке, когда вы пишете «ABC», чтобы сказать «Пожалуйста, введите число» < /p>
< Br />import java.util.Scanner;

public class calculator
{
public static void main(String[] args0) {
Scanner test = new Scanner(System.in);

int x;
int y;
String c;

System.out.println("Insert a number ");
x = test.nextInt();

System.out.println("insert a value e.g * / + -");
c = test.next();

System.out.println("Insert another number");
y = test.nextInt();

if ( c.equals("*")) {
System.out.println("the total is " + x*y);
}

if (c.equals("+")) {
System.out.println("the total is " + (x+y));

}

if (c.equals("-")) {
System.out.println("the total is "+ (x-y));
}

if (c.equals("/")) {
System.out.println("the total is "+ (x/y));
}

}
}


Подробнее здесь: https://stackoverflow.com/questions/506 ... mbers-only

Вернуться в «JAVA»