๐งช Step 1: Import the Scanner
Before using it, you need to import it at the top of your code:
Before using it, you need to import it at the top of your code:
import java.util.Scanner;
✏️ Example: Asking for a Name
import java.util.Scanner;
public class InputExample {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Create Scanner
System.out.print("What's your name? ");
String name = input.nextLine(); // Read a line of text
System.out.println("Hello, " + name + "!");
}
}
When I first heard of Java, I thought it was just something to do with Minecraft mods or Android apps. I didn’t realize it would become my...
No comments:
Post a Comment