0
what's wrong with my code ?
import java.util.scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner (System.in); System.out.println("donner votre age"); int age = sc.nextInt(); if (age < 15){ System.out.println("mineur"); } else { System.out.println("majeur"); } } }
13 Answers
+ 3
The scanner on line 1 needs to be capitalized. I just ran the code after fixing that and it seems to be working fine.
If you are not already I would suggest coding on a program that shows which line the error is on. I use eclipse and I find it very helpful.
+ 1
Code is correct. I have tried.
Only in first line a little wrong.
import java.util.Scanner; needed.
+ 1
The yellow is just telling you that the scanner is not closed. The same thing shows up before you use variable. Its just a warning.
+ 1
thanks @parker L
0
thanks but it didn't solve my problem .
0
What does your compiler say the problem is?
0
@Ousmane
the compiler give this :
donner votre age
majeur
0
i fixed the problem by deleting the :
System.out.println("donner votre age");
but what if i want to keep that line of code too ? i think im missing something !
0
it seem to be running perfectly in eclipse but one thing i noticed with sc in the first scanner line eclipse mention sc in yellow smthing wrong with it !
0
Np Glad to help
- 1
hi Yassie, use sc.close(); before if loop. This will close the scanner.
- 2
There is a space before you passed in System.in.
So replace it with this Scanner sc = new Scanner(System.in);
- 2
i may be wrong, but try to return age after your else ex:
return age;
i think that might work, just try it and let me know if im right or not