+ 1

Donde está el error

Pro algún motivo nunca imprime la primera opción y si la primera opción es 0 tira un error. No entiendo que está mal https://code.sololearn.com/c16h0Q0A3bJ4/?ref=app

25th Oct 2020, 1:29 PM
Rodrigo Marsan
Rodrigo Marsan - avatar
6 Answers
+ 1
You input variable number only once. If it is 0 your program will end otherwise it will loop forever.
25th Oct 2020, 2:13 PM
Paul
Paul - avatar
+ 1
Like this it works, please look at the comments for what i changed: import java.util.Scanner; public class Main { public static int numero ; // added global var numero public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // removed input //tu código va aquí // removed if statement do { numero = scanner.nextInt(); // removed int if (numero == 1){ System.out.println("Language selection"); } if (numero == 2){ System.out.println("Customer support"); } if (numero == 3){ System.out.println("Check the balance"); } if (numero == 4){ System.out.println("Check the loan balance"); } if (numero == 0){ System.out.println("Exit"); } } while (numero != 0); // changed number to nunero } }
25th Oct 2020, 2:40 PM
Paul
Paul - avatar
+ 1
The input at sololearn is odd, you have to give all your input on separate lines before you push submit: https://code.sololearn.com/cRzePwPL5oY8/?ref=app
25th Oct 2020, 3:01 PM
Paul
Paul - avatar
0
thanks a lot!
25th Oct 2020, 2:49 PM
Rodrigo Marsan
Rodrigo Marsan - avatar
0
I have tried the code you wrote but it seems it doesnt work. Could you post a link to where I can run it and chek it? Thanks again
25th Oct 2020, 2:52 PM
Rodrigo Marsan
Rodrigo Marsan - avatar
0
it works great! thanks a lot. I am just beggining at programming so I get confused many times. Thanks for your help
25th Oct 2020, 3:03 PM
Rodrigo Marsan
Rodrigo Marsan - avatar