0

I cannot find what is wrong with my code. please help

I am fairly new in java and it seems like the compiler thinks In is a variable? please help import java.text.*; import java.io.*; public class JavaApplication2 { public static void main (String[] args) { int num = In.getInt (); int[] arr = new int [9]; int sum = 0, sum1 = 0, sum2 = 0; for (int i = 8 ; i >= 0 ; i--) { arr [i] = num % 10; num /= 10; System.out.println(arr[i]); } for (int i = 0 ; i <= 8 ; i += 2) { arr [i] += sum2; } for (int i = 1 ; i <= 8 ; i += 2) { arr [i] *= 2; arr [i] += sum; System.out.println(arr[i]); } if (10 - ((sum + sum2) % 10) != arr [8]) System.out.println ("Not Valid"); else { System.out.println ("Valid"); } } } File: /Users/r/JavaApplication2.java [line: 6] Error: /Users/r/JavaApplication2.java:6: cannot find symbol symbol : variable In location: class JavaApplication2

7th Jan 2018, 4:05 AM
Ray Wang
Ray Wang - avatar
1 Answer
+ 1
//problem in getting/reading number import java.text.*; import java.io.*; import java.util.Scanner ; public class JavaApplication2 { public static void main (String[] args){ Scanner sc= new Scanner(System.in); int num = sc.nextInt(); int[] arr = new int [9]; int sum = 0, sum1 = 0, sum2 = 0; for (int i = 8 ; i >= 0 ; i--) { arr [i] = num % 10; num /= 10; System.out.println(arr[i]); } for (int i = 0 ; i <= 8 ; i += 2) { arr [i] += sum2; } for (int i = 1 ; i <= 8 ; i += 2) { arr [i] *= 2; arr [i] += sum; System.out.println(arr[i]); } if (10 - ((sum + sum2) % 10) != arr [8]) System.out.println ("Not Valid"); else { System.out.println ("Valid"); } } }
7th Jan 2018, 4:13 AM
Elie Douaihy
Elie Douaihy - avatar