New to Java Programming - Error help

Posted by JJJ on Ask Ubuntu See other posts from Ask Ubuntu or by JJJ
Published on 2012-06-17T15:19:59Z Indexed on 2012/06/17 15:23 UTC
Read the original article Hit count: 225

Filed under:
|
|
|

I am going through a Java book and drafting the examples and have run into the following error when compiling this code. Any help would be appreciated thank you.

Error: Main.java:3: class Addition is public, should be declared in a file named Addition.java public class Addition        ^

1 error

Code:

import java.io.*; import java.util.Scanner; public class Addition

{   public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); 

int number1;
int number2;
int sum;

System.out.print( "Enter first digit: " );
number1 = input.nextInt();

System.out.print( "Enter second digit:" );
number2 = input.nextInt();

sum = number1 + number2;

System.out.printf( "Sum is %d\n, sum" );

     } }

© Ask Ubuntu or respective owner

Related posts about java

Related posts about error