7 Replies Latest reply: Jan 12, 2013 7:14 AM by 982162 RSS

    Simple java program that has a few errors

    982162
      Greetings to everone

      I was fiddling around with some pseudocode and thought of using it with java, see following code and error , it basically finds whether the number inputted is even.
      import java.util.*;
      import java.io.*;
      
             public class modulo
      
       {
            Scanner readone = new Scanner(System.in);
            int num1;
            System.out.println("Please enter a number:   ");
            num1 = readone.nextInt();
         
            public static void main(String [] moD)
      
        {
              
              int num2 = num1 %2;
         
                   if(num2 ==0)
                { 
                     System.out.println("The inputted number is even");
                }
         }
      
      
      }                                                                                         
      
       
      Below are the errors i get, what i have in mind is that the variables and scanner should be declared within the void main, please correct me if i'm worng guyz

      modulo.java:9: <identifier> expected
      System.out.println("Please enter a number: ");
      ^
      modulo.java:9: illegal start of type
      System.out.println("Please enter a number: ");
      ^
      modulo.java:10: <identifier> expected
      num1 = readone.nextInt();
      ^
      3 errors


      Yours sincerely

      Thanks,
      Hamad