Saturday, 19 April 2025

Taking User Input in Java (with Scanner)

 

๐Ÿงช Step 1: Import the Scanner

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 + "!"); } }




No comments:

Post a Comment

๐Ÿ‘จ‍๐Ÿ’ป How I Started Learning Java at 15 (and You Can Too)

  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...