Learning Java/Basic Java Language: Difference between revisions

Content deleted Content added
→‎Asking the user: Changed section heading.
Line 355:
If, when running, it reports "invalid class file", the compiler might not have created a file. It should have given an error message at compile time.
 
== AskingUser the userInput ==
 
The first way to get user input is from the keyboard without using the swing gui. You must first import the Scanner package first like so. <code>import java.util.Scanner;</code> Once you have done that you will have to create a Scanner object. <code>Scanner scan1 = new Scanner(System.in);</code> Finally after the user has entered the input asked for you retrieve using your Scanner object. For example if we wanted a string as input we could use the following code.