List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:MainClass.java
public static void main(String args[]) { Scanner input = new Scanner(System.in); int x;/*from w w w .ja va 2s . c om*/ int y; int z; int result; System.out.print("Enter first integer: "); x = input.nextInt(); System.out.print("Enter second integer: "); y = input.nextInt(); System.out.print("Enter third integer: "); z = input.nextInt(); result = x * y * z; System.out.printf("Product is %d\n", result); }
From source file:Main.java
public static void main(String[] args) { Scanner scn = new Scanner(System.in); String userName;//from w ww .jav a2s.c o m System.out.println("Enter your email address: "); userName = scn.findInLine(Pattern.compile("[a-z]+")); System.out.println(userName); }
From source file:Main.java
public static void main(String[] ap) { int val; try {// w ww.ja v a2s . c om Scanner sc = new Scanner(System.in); // Requires J2SE 1.5 val = sc.nextInt(); } catch (NumberFormatException ex) { System.err.println("Not a valid number: " + ex); return; } System.out.println("I read this number: " + val); }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("c:/text.txt")); System.out.println(scanner.nextLine()); scanner.close();/*from w w w .j a v a2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { String str = "start 1 2 123455"; Scanner sc = new Scanner(str); String param1 = sc.next();/* ww w. ja v a2 s. c om*/ int param2 = sc.nextInt(); int param3 = sc.nextInt(); int param4 = sc.nextInt(); System.out.println(param1 + "\t" + param2 + "\t" + param3 + "\t" + param4); }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt")); System.out.println(scanner.nextLine()); scanner.close();// ww w . j a v a 2 s. c om }
From source file:MainClass.java
public static void main(String args[]) throws IOException { Scanner src = new Scanner("1,2,3,4"); src.useDelimiter(", *"); System.out.println(src.delimiter()); }
From source file:MainClass.java
public static void main(String args[]) { Scanner input = new Scanner(System.in); int number1;// w w w . ja v a 2 s. c o m int number2; System.out.print("Enter first integer: "); // prompt number1 = input.nextInt(); // read first number from user System.out.print("Enter second integer: "); // prompt number2 = input.nextInt(); // read second number from user if (number1 == number2) System.out.printf("%d == %d\n", number1, number2); if (number1 != number2) System.out.printf("%d != %d\n", number1, number2); if (number1 < number2) System.out.printf("%d < %d\n", number1, number2); if (number1 > number2) System.out.printf("%d > %d\n", number1, number2); if (number1 <= number2) System.out.printf("%d <= %d\n", number1, number2); if (number1 >= number2) System.out.printf("%d >= %d\n", number1, number2); }
From source file:Main.java
public static void main(String[] args) { System.out.println("Enter a string"); Scanner input = new Scanner(System.in); String s1 = input.nextLine(); s1 = s1.trim();/* w w w . j av a 2 s . co m*/ int howLong = s1.length(); for (int counter = 0; counter < howLong; counter++) { char ch = s1.charAt(counter); System.out.print(ch); } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0"; Scanner scanner = new Scanner(s); // print the next line of the string System.out.println(scanner.nextLine()); scanner.close();//from w w w .j a v a 2 s . co m }