The definition of your class is incorrect. You are trying to define two classes: ScannerDemo and Main . Replace:
class ScannerDemo public class Main
Using only:
public class ScannerDemo
In addition, in your Main method, you must reference the variable userName instead of userName , and you do not define username2 . Please note that Java identifiers are case sensitive:
public static void main (String [] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); String userName = sc.nextLine(); System.out.println("your number is" + username + "enter your next number"); String username2 = sc.nextline(); System.out.println("your total is" + username2 ); }
source share