Skip to content

YuriiJavaDev/JavaBasics_Task_20

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Login System (JavaBasics_Task_20)

📌 Description

This project demonstrates how to handle user input in Java using the Scanner class to read and display a password from the keyboard.

🚀 Task Requirements

  • Initialize the Scanner object for reading from System.in.
  • Read exactly one line of text using the nextLine() method.
  • Store the input in a String variable.
  • Print the entered password to the console for confirmation.

🛠 Technical Stack

  • Language: Java 23 (Current version).
  • IDE: IntelliJ IDEA.
  • Concepts: Standard Input (System.in), Scanner class, String Handling.

⌨️ Practical Implementation

This task introduces the Scanner utility, which acts as a bridge between the user's keyboard and the program. By using nextLine(), we ensure that the entire sequence of characters (including spaces) is captured until the user presses Enter.

Why this approach?

  1. Interactivity: It allows the program to process dynamic data provided at runtime instead of hardcoded values.
  2. Standard Practice: Using Scanner with System.in is the fundamental way to build console applications in Java.
  3. Robustness: nextLine() is safer than next() because it reads the full line, preventing issues with trailing newline characters in more complex input scenarios.

📋 Example Output

Enter your password: 
qwerty123
Your password is: qwerty123

💻 Code Example

package com.yurii.pavlenko;

import java.util.Scanner;

/**
 * Task 20: Simple Login Input.
 * Demonstrates reading user input from the console using the Scanner class.
 */
public class Task_20_App {
    public static void main(String[] args) {
        // 1. Create a Scanner object to read input from the keyboard (System.in)
        Scanner scanner = new Scanner(System.in);

        // 2. Prompt the user to enter a single line as a password
        // and read the input into the password variable.
        System.out.println("Enter your password:");
        String password = scanner.nextLine();

        // 3. Output the entered password to the screen
        System.out.println("Your password is: ");
        System.out.println(password);

        // 4. Close the scanner to free up system resources.
        scanner.close();
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a learning project. JavaBasics_Task_20: Implementing reading user input using Scanner and nextLine. 170126_1109

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages