How to bring up the console in Java

There are two common methods to bring up the console in Java:

  1. Use the static method out of the System class to print output to the console.
System.out.println("Hello, World!");
  1. Get console input using the Scanner class.
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Enter your name: ");
        String name = scanner.nextLine();
        
        System.out.println("Hello, " + name + "!");
    }
}

This way, you can invoke the console in a Java program and perform input and output operations.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds