List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:Main.java
public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Please enter elements..."); char[] a = sc.next().toCharArray(); System.out.println("Array elements are : "); for (int i = 0; i < a.length; i++) System.out.println(a[i]); }
From source file:Main.java
public static void main(String[] args) { Scanner scanInput = new Scanner(System.in); String input = scanInput.nextLine(); System.out.println("The input is : " + input); }
From source file:Main.java
public static void main(String args[]) { Scanner sc = new Scanner("Name: Tom Age: 28 ID: 77"); sc.findWithinHorizon("ID:", 100); if (sc.hasNext()) System.out.println(sc.next()); else/*w w w . ja v a2s. c om*/ System.out.println("Error!"); }
From source file:Main.java
public static void main(String[] args) { Scanner input = new Scanner(System.in); String confirm = "y"; do {//from w w w .java 2s. c om System.out.println("Welcome to Java Programming!"); System.out.println("Print Again? (y/n)"); confirm = input.nextLine(); } while (confirm.equalsIgnoreCase("y")); }
From source file:MainClass.java
public static void main(String args[]) { Scanner sc = new Scanner("Name: Tom Age: 28 ID: 77"); sc.findWithinHorizon("ID:", 0); if (sc.hasNext()) System.out.println(sc.next()); else//from w w w . j a v a 2 s.com System.out.println("Error!"); }
From source file:MainClass.java
public static void main(String args[]) { Scanner sc = new Scanner("Name: Tom Age: 28 ID: 77"); sc.findWithinHorizon("IDs:", 0); if (sc.hasNext()) System.out.println(sc.next()); else// ww w .j a v a2s .c o m System.out.println("Error!"); }
From source file:Main.java
public static void main(String[] args) { Scanner input = new Scanner(System.in); String answer = input.nextLine(); if ("yes".equals(answer)) { System.out.println("Yea!"); } else {/*from w ww . ja va 2s. co m*/ System.out.println("No :("); } }
From source file:MainClass.java
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.next();/* www . j a va 2 s .c o m*/ System.out.println(s); }
From source file:Main.java
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Username: "); String username = scanner.nextLine(); System.out.print("Password: "); String password = scanner.nextLine(); System.out.print("What is 2 + 2: "); int result = scanner.nextInt(); if (username.equals("admin") && password.equals("secret") && result == 4) { System.out.println("Welcome"); } else {//from w w w . ja v a 2 s .c o m System.out.println("Invalid username or password!"); } }
From source file:MainClass.java
public static void main(String args[]) { Scanner conin = new Scanner(System.in); int count = 0; System.out.println("Enter numbers to average."); while (conin.hasNext()) { if (conin.hasNextDouble()) { System.out.println(conin.nextDouble()); count++;//from w w w. j a v a2s .co m } if (count == 3) { System.exit(0); } } }