Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

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); } }

OpenStudy (mandre):

What do you want it to do and what is it doing?

OpenStudy (harsha19111999):

Hey

OpenStudy (harsha19111999):

I identified where you did wrong. You have to include " Scanner input = new Scanner (System.in); " in the " public static void main(String args[]) "

OpenStudy (lyrae):

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) ... } ```

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!