How to solve illegal character in Scanner issue. Inputs are integers | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to solve illegal character in Scanner issue. Inputs are integers

Code on computer works perfect but here on phone Its saying illegal character. I think its '\n' but inputs are with integers. import java.util.*; public class Program{ public static void main(String[] args) { Ā  Ā Scanner sc = new Scanner(System.in); Ā  Ā ArrayList<Integer> arr = new ArrayList<Integer>(); Ā  Ā for(int i = 0; i < 6; i++){ Ā  Ā  Ā  Ā arr.add(sc.nextInt()); Ā  Ā } Ā  Ā  Ā for(int i = 0; i < arr.size(); i++){ Ā  Ā  Ā  Ā if(arr.get(i) % 3 == 0){ Ā  Ā  Ā  Ā  Ā  Ā System.out.print("Pop "); Ā  Ā  Ā  Ā }else if(arr.get(i) % 2 == 0){ Ā  Ā  Ā  Ā  Ā  Ā System.out.print("Cracle "); Ā  Ā  Ā  Ā }else if(arr.get(i) % 3 != 0 && arr.get(i) % 2 != 0 ){ Ā  Ā  Ā  Ā  Ā  Ā System.out.print("Snap "); Ā  Ā  Ā  Ā } Ā  Ā } } }

22nd Apr 2020, 12:53 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
10 Respostas
+ 3
Check again :) import java.util.*; public class Program{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); ArrayList<Integer> arr = new ArrayList<Integer>(); for(int i = 0; i < 6; i++){ arr.add(sc.nextInt()); } for(int i = 0; i < arr.size(); i++){ if(arr.get(i) % 3 == 0){ System.out.print("Pop "); } else if(arr.get(i) % 2 == 0){ System.out.print("Cracle "); } else if(arr.get(i) % 3 != 0 && arr.get(i) % 2 != 0 ){ System.out.print("Snap "); } } } }
22nd Apr 2020, 1:18 PM
Daljeet Singh
Daljeet Singh - avatar
+ 2
Try writing the whole code again on sololearn code playground. This occurs because you must have copy pasted the code from your computer.
22nd Apr 2020, 1:02 PM
Avinesh
Avinesh - avatar
+ 2
You said that you did "on your computer " then you must have copy-pasted the snippet thats why illegal chars editĀ®Marko Bitenc I only removed those, rest of you code is intact šŸ‘
22nd Apr 2020, 2:26 PM
Daljeet Singh
Daljeet Singh - avatar
+ 2
I have just realized that it was a code-coach problem, for that you have to check spellings and while importing avoid using * only import what is necessary //same for DM, I edited my last answer for that :)
25th Apr 2020, 3:20 PM
Daljeet Singh
Daljeet Singh - avatar
+ 1
No i did it first here then on my computer to see what is going on.
22nd Apr 2020, 1:05 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
+ 1
Yes works :) thanku you. ok where was issue?
22nd Apr 2020, 1:26 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
+ 1
Thank you
25th Apr 2020, 3:21 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
0
But i will rewrite it again and see if works anyway
22nd Apr 2020, 1:07 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
0
No, first i made here like i always do. It happen some time as i delete something and proceed
22nd Apr 2020, 2:30 PM
šŸ”¹Marko B.šŸ”¹
šŸ”¹Marko B.šŸ”¹ - avatar
- 1
queen_h94
3rd Jun 2022, 11:25 AM
Um Thamer