List of usage examples for java.util Scanner next
public String next()
From source file:com.super_bits.modulos.paginas.adminTools.PgAdminContainerObjetoTest.java
public static void main(String[] paramentros) { // Ask for user input System.out.print("Enter 1st value:"); // use scanner to read the console input Scanner scan = new Scanner(System.in); String valor = scan.next(); double valorAtualizado = Double.parseDouble(valor) * 8.333; double calculoMultiplo = 10 * (Math.ceil(Math.abs(valorAtualizado / 10))); System.out.println(calculoMultiplo); double teste = (double) Math.round(Double.parseDouble(valor) * 8.3d) * 10 / 10d; System.out.println("TEste:" + teste); System.out.println("Result of the operation is " + valor); System.out.println(Precision.round(0.912385, 0, BigDecimal.ROUND_HALF_UP)); int yourScale = 10; System.out.println(BigDecimal.valueOf(0.42344534534553453453 - 0.42324534524553453453).setScale(yourScale, BigDecimal.ROUND_HALF_UP)); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Float f = 1.2385f;/*from w w w . j a v a2s . com*/ s = s + f; Scanner scanner = new Scanner(s); scanner.useLocale(Locale.US); while (scanner.hasNext()) { scanner.next(); if (scanner.hasNextFloat()) { System.out.println("Found :" + scanner.nextFloat()); } } scanner.close(); }
From source file:LogTest.java
public static void main(String[] args) throws IOException { String inputfile = args[0];//from w w w. ja v a2 s. c o m String outputfile = args[1]; Map<String, Integer> map = new TreeMap<String, Integer>(); Scanner scanner = new Scanner(new File(inputfile)); while (scanner.hasNext()) { String word = scanner.next(); Integer count = map.get(word); count = (count == null ? 1 : count + 1); map.put(word, count); } scanner.close(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); PrintWriter out = new PrintWriter(new FileWriter(outputfile)); for (String key : keys) out.println(key + " : " + map.get(key)); out.close(); }
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 ww w .j a va2 s .c o m 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// w w w . j av a 2s . c o m System.out.println("Error!"); }
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/*from w w w . j a v a2 s . c om*/ System.out.println("Error!"); }
From source file:MainClass.java
public static void main(String args[]) { String instr = "Name: Joe Age: 28 ID: 77"; Scanner conin = new Scanner(instr); conin.findInLine("Age:"); // find Age if (conin.hasNext()) System.out.println(conin.next()); else/*from w w w .j a v a 2 s . c om*/ System.out.println("Error!"); }
From source file:sustenanceSrc.Main.java
@SuppressWarnings("resource") public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.println("What ingredients do you want to use Boss?"); String ingredients = reader.next(); ingredients = ingredients.replace(",", "%2C"); findByIngredients(ingredients);// w ww. j av a 2 s .co m }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("data.txt"); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter(","); while (lineScanner.hasNext()) { String part = lineScanner.next(); System.out.print(part + ", "); }//from w w w .ja v a 2s .c o m System.out.println(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("fileName")); scanner.useDelimiter(System.getProperty("line.separator")); while (scanner.hasNext()) { parseLine(scanner.next()); }/* w w w.j a va 2 s.c o m*/ scanner.close(); }