This discussion is archived
7 Replies Latest reply: Jan 12, 2013 5:14 AM by 982162 RSS

Simple java program that has a few errors

982162 Newbie
Currently Being Moderated
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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points