why is this code not working? package onlineclass; import java.util.Scanner; public class Assignment1 { Scanner input = new Scanner (System.in); public static void main(String[] args) { int numbers; int num1,num2,num3,num4,num5; System.out.printf("Enter a 5 digit number"); numbers = input.nextInt () ; num1=numbers/10000; num2=numbers%10000/1000; num3=numbers%10000%1000/100; num4=numbers%10000%1000%100/10; num5=numbers%10000%1000%100%10; System.out.printf(num1+" "+num2+" "+num3+" "+num4+" "+num5); } }
What do you want it to do and what is it doing?
Hey
I identified where you did wrong. You have to include " Scanner input = new Scanner (System.in); " in the " public static void main(String args[]) "
main is a static method and you cannot use a non-static variable in a static context (inside a static method). Either add a static modifier to declaration of input ``` static Scanner input = new Scanner (System.in) ``` or move the delaration of input inside main (as @Harsha19111999 suggested) ``` public static void main(String[] args) { Scanner input = new Scanner (System.in) ... } ```
Join our real-time social learning platform and learn together with your friends!