0

What am I doing Wrong in the following code?

import java.util.Scanner; public class Program { public static void main(String[] args) { //variables int firstNumber, secondNumber; String operation, a; //user input Scanner sc = new Scanner(System.in); System.out.println("Enter the first integer"); firstNumber = sc.nextInt(); System.out.println("Enter the operation in words(add, substract, multiply, devide):"); a = sc.nextLine(); operation = a.toLowerCase(); System.out.println("Enter the second integer"); secondNumber = sc.nextInt(); System.out.println(firstNumber); System.out.println(secondNumber); System.out.println(operation ); } }

31st Jul 2020, 3:41 PM
Pankaj Kumar Panda
Pankaj Kumar Panda - avatar
5 Respostas
31st Jul 2020, 3:53 PM
minirkk
minirkk - avatar
+ 1
👆Take a look at above post... And Input in the form: int String int Ex: 4 string 5
31st Jul 2020, 4:56 PM
Jayakrishna 🇮🇳
+ 1
After firstNumber = sc.nextInt(); You have to add "sc.nextLine();" - it will consume "\n" - new line
31st Jul 2020, 5:14 PM
Michal
Michal - avatar