Handling User Inputs & Type Conversion
Using the .nextLine() method
.nextLine() method// Example Program
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a line of text: ");
String inputLine = sc.nextLine();
System.out.println("You entered: " + inputLine);
sc.close();
}
}Closing your Scanner object
Scanner objectType Conversion
Integer.parseInt(String obj)
Integer.parseInt(String obj)Integer.toString(int obj)
Integer.toString(int obj)Other Type Conversion Methods:
Last updated