+ 1
I need source code to read an integer in java
Pls answer me
3 Respostas
+ 13
int integer = scanner.nextInt();
or
int integer = Integer.parseInt(scanner.nextLine());
+ 3
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = Integer.valueOf(sc.nextLine().replaceAll("\\D", ""));
System.out.print(x);
}
}
---
Don't forget sc.nextLine() can recieve numbers, words and numbers with letters. So you need to use regex.