List of usage examples for java.util Scanner next
public String next()
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(); 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:MainClass.java
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.next(); System.out.println(s);//from ww w .ja v a 2s . c o m }
From source file:Main.java
public static void main(String[] args) { String str = "java2s.com"; ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes()); System.setIn(bais);/* ww w . j a v a2s . c om*/ Scanner scanner = new Scanner(System.in); String input = scanner.next(); System.out.println(input); }
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) { String s = "java2s.com 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); // find the next token and print it System.out.println(scanner.next()); // find the next token and print it System.out.println(scanner.next()); scanner.close();//from w w w . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { Console cnsl = System.console(); if (cnsl != null) { System.out.print("Enter name : "); Scanner scan = new Scanner(cnsl.reader()); while (scan.hasNext()) { String str = scan.next(); System.out.println(str); }// www .j a va 2 s. c o m } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true 9000000000000000000000L"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong(20)); }//from ww w .ja v a 2 s . c o m } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Long l = 123456789098765432L; s = s + l;//from w w w . j av a 2s. c o m Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong()); } } scanner.close(); }
From source file:SetTest.java
public static void main(String[] args) { Set<String> words = new HashSet<String>(); // HashSet implements Set long totalTime = 0; Scanner in = new Scanner(System.in); while (in.hasNext()) { String word = in.next(); long callTime = System.currentTimeMillis(); words.add(word);//from w w w. ja v a2 s . c o m callTime = System.currentTimeMillis() - callTime; totalTime += callTime; } Iterator<String> iter = words.iterator(); for (int i = 1; i <= 20 && iter.hasNext(); i++) System.out.println(iter.next()); System.out.println(". . ."); System.out.println(words.size() + " distinct words. " + totalTime + " milliseconds."); }
From source file:Main.java
public static void main(String[] args) { String content = " <2008-10-07> hi <test>" + " <2008-11-26> user <test>" + " <2008-11-28><aaaa> "; Scanner sc = new Scanner(content).useDelimiter("\\s*[<>]\\s*"); while (sc.hasNext()) { System.out.printf("[%s|%s|%s]%n", sc.next(), sc.next(), sc.next()); if (sc.hasNext()) sc.next();/*from w ww . ja v a 2s . co m*/ } }