I need to know how to get Strings being printed on the console to do some sort of processing on them.
I need to know how to get Strings being printed on the console to do some sort of processing on them.
You need to use the Scanner
class and instantiate it passing System.in
as a parameter.
Scanner scanner = new Scanner(System.in);
System.out.println("Entre com seu nome:");
String nome = scanner.nextLine();
Complete example
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Entre com seu nome:");
String nome = scanner.nextLine();
System.out.printf("Seu nome é %s", nome);
}
}
try (Scanner scanner = new Scanner(System.in)) {
System.out.println("Entre com seu nome:");
String nome = scanner.nextLine();
System.out.printf("Seu nome é %s", nome);
} catch (Exception e) {
e.printStackTrace();
}