+ 1

Can someone please tell me how to fix the error in the last line of code? Eclipse said TABLE1 cannot be resolved to a variable

import java.util.Scanner; public class TableDeMultiplication { public static void main(String[] args) { // Tables de Multiplication Scanner clavier = new Scanner(System.in); do { System.out.println("Quelle table de multiplication vous interesse?"); final int TABLE1 = clavier.nextInt(); System.out.println("Quelle est la limite de votre multiplicateur?"); final int MULTIP1 = clavier.nextInt(); if(TABLE1>=0 && MULTIP1>=0) { for( int i=0; i<=MULTIP1; i++) { System.out.println( TABLE1 + " multiplié par " + i + " est égal à: " + (TABLE1*i)); } } else { System.out.println("Vous devez rentrer des nombres positifs!");}; } while(TABLE1<=0 || MULTIP1<=0); } }

16th Aug 2018, 3:52 PM
Weiner-Kervens Pierre
Weiner-Kervens Pierre - avatar
7 Respuestas
+ 5
Here you go ... //Can someone please tell me how to fix the error in the last line of code? Eclipse said TABLE1 cannot be resolved to a variable import java.util.Scanner; public class TableDeMultiplication { public static void main(String[] args) { // Tables de Multiplication Scanner clavier = new Scanner(System.in); int TABLE1, MULTIP1; do { System.out.println("Quelle table de multiplication vous interesse?"); TABLE1 = clavier.nextInt(); System.out.println("Quelle est la limite de votre multiplicateur?"); MULTIP1 = clavier.nextInt(); if(TABLE1>=0 && MULTIP1>=0) { for( int i=1; i<=MULTIP1; i++) { System.out.println( TABLE1 + " multiplié par " + i + " est égal à: " + (TABLE1*i)); } } else { System.out.println("Vous devez rentrer des nombres positifs!"); } } while(TABLE1<=0 || MULTIP1<=0); } }
16th Aug 2018, 4:19 PM
Ipang
+ 3
Looks like the variable TABLE1in the condition is out of scope. define it at the start, before the "do" block instead...
16th Aug 2018, 3:59 PM
ifl
ifl - avatar
+ 3
Also, you may not want to define TABLE1 as final as it is supposed to be a variable, not a constant....
16th Aug 2018, 4:01 PM
ifl
ifl - avatar
+ 3
Same for MULTIPL by the way....
16th Aug 2018, 4:02 PM
ifl
ifl - avatar
+ 1
thank you very much
16th Aug 2018, 4:33 PM
Weiner-Kervens Pierre
Weiner-Kervens Pierre - avatar
+ 1
it works right now
16th Aug 2018, 4:34 PM
Weiner-Kervens Pierre
Weiner-Kervens Pierre - avatar
0
i did it but now I have an infinite loop with the "else" statement
16th Aug 2018, 4:04 PM
Weiner-Kervens Pierre
Weiner-Kervens Pierre - avatar