-4

I like to read from a console in Java. What is the most convenient way to do it for the sake of the processing of the input? For example I want to read a single char or an integer.

Marjan100
  • 346
  • 1
  • 2
  • 16

2 Answers2

1
import java.util.Scanner;

Scanner input = new Scanner(System.in);
int toBeRead = Integer.parseInt(input.nextLine());
MMelvin0581
  • 509
  • 6
  • 20
  • Be aware that `replace()` and `replaceAll()` are both slow because many many string objects are created inside the method call: https://stackoverflow.com/questions/6262397/string-replaceall-is-considerably-slower-than-doing-the-job-yourself – T Tse Apr 19 '18 at 19:10
0

import java.util.Scanner

Scanner sc=new Scanner(System.in); sc.nextInt();

Null
  • 36
  • 3