How to get user input in Java

In Java, we can use java.util.Scanner to get user input from console. 1. Scanner 1.1 Read a line. UserInputExample1.java package com.mkyong; import java.util.Scanner; public class UserInputExample1 { public static void main(String[] args) { // auto close scanner try (Scanner scanner = new Scanner(System.in)) { System.out.print("Enter something : "); String input = scanner.nextLine(); // Read user …

Read more

Android prompt user input dialog example

In this tutorial, we will enchance the previous AlertDialog example, to make it able to accept user input, just like a PromptDialog. More specific, this is a custom AlertDialog example. See following steps : Create a prompt dialog layout (XML file). Attach the prompt dialog layout to AlertDialog.Builder. Attach the AlertDialog.Builder to AlertDialog. Done. P.S …

Read more