List of usage examples for java.util Scanner nextBoolean
public boolean nextBoolean()
From source file:Main.java
public static void main(String[] args) { String s = "Hello true World! 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is boolean, print found and the boolean if (scanner.hasNextBoolean()) { System.out.println("Found :" + scanner.nextBoolean()); }/*from ww w. j a v a2 s .com*/ // if a boolean is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { // Write output to a file. FileWriter fout = new FileWriter("test.txt"); fout.write("int: 1 double 1.0 boolean true"); fout.close();/*from w w w.j a va2 s . c o m*/ FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { System.out.println("int: " + src.nextInt()); } else if (src.hasNextDouble()) { System.out.println("double: " + src.nextDouble()); } else if (src.hasNextBoolean()) { System.out.println("boolean: " + src.nextBoolean()); } else { System.out.println(src.next()); } } fin.close(); }
From source file:ScanMixed.java
public static void main(String args[]) throws IOException { int i;/*from w w w .ja v a 2 s.c o m*/ double d; boolean b; String str; FileWriter fout = new FileWriter("test.txt"); fout.write("Testing Scanner 10 12.2 one true two false"); fout.close(); FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { i = src.nextInt(); System.out.println("int: " + i); } else if (src.hasNextDouble()) { d = src.nextDouble(); System.out.println("double: " + d); } else if (src.hasNextBoolean()) { b = src.nextBoolean(); System.out.println("boolean: " + b); } else { str = src.next(); System.out.println("String: " + str); } } fin.close(); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { int i;//from w w w . j a v a2 s . com double d; boolean b; String str; FileWriter fout = new FileWriter("test.txt"); fout.write("string true false 1 2 3 4.12"); fout.close(); FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { i = src.nextInt(); System.out.println("int: " + i); } else if (src.hasNextDouble()) { d = src.nextDouble(); System.out.println("double: " + d); } else if (src.hasNextBoolean()) { b = src.nextBoolean(); System.out.println("boolean: " + b); } else { str = src.next(); System.out.println("String: " + str); } } fin.close(); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { int i;//from ww w.j a v a2 s . co m double d; boolean b; String str; FileWriter fout = new FileWriter("test.txt"); fout.write("Testing Scanner 10 12.2 one true two false"); fout.close(); FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { i = src.nextInt(); System.out.println("int: " + i); } else if (src.hasNextDouble()) { d = src.nextDouble(); System.out.println("double: " + d); } else if (src.hasNextBoolean()) { b = src.nextBoolean(); System.out.println("boolean: " + b); } else { str = src.next(); System.out.println("String: " + str); } } fin.close(); }
From source file:Main.java
static void parseLine(String line) { Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter("\\s*,\\s*"); String name = lineScanner.next(); int age = lineScanner.nextInt(); boolean isCertified = lineScanner.nextBoolean(); System.out.println("It is " + isCertified + " that " + name + ", age " + age + ", is certified."); }
From source file:com.tesora.dve.tools.CLIBuilder.java
protected Boolean scanBoolean(Scanner scanner, String exists) throws PEException { if (hasRequiredArg(scanner, exists)) { try {/*from w w w . jav a 2 s . c om*/ return scanner.nextBoolean(); } catch (final Exception e) { throw new PEException("Failed to parse boolean parameter", e); } } return null; }
From source file:ehospital.Principal.java
private void btn_cargar_ambuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_ambuMouseClicked // TODO add your handling code here: Scanner sc = null; File archivo2;//from w w w . j a v a 2 s .c om try { archivo2 = new File("./Ambulancia.txt"); sc = new Scanner(archivo2); sc.useDelimiter(","); while (sc.hasNext()) { Ambulancias ambu = new Ambulancias(sc.next(), sc.nextInt(), sc.nextInt(), new Lugar(sc.next()), sc.nextBoolean()); lista_ambu.add(ambu); } JOptionPane.showMessageDialog(null, "Ambulancias Cargadas"); } catch (Exception e) { } finally { sc.close(); } System.out.println(lista_ambu.toString()); }
From source file:ehospital.Principal.java
private void btn_cargar_paramMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cargar_paramMouseClicked // TODO add your handling code here: Scanner sc = null; File archivo2;//from w w w . j a v a2 s. c om try { archivo2 = new File("./Paramedicos.txt"); sc = new Scanner(archivo2); sc.useDelimiter(","); while (sc.hasNext()) { Paramedicos param = new Paramedicos(sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), new Lugar(sc.next()), sc.nextBoolean()); lista_param.add(param); } JOptionPane.showMessageDialog(null, "Paramedicos Cargadas"); } catch (Exception e) { } finally { sc.close(); } System.out.println(lista_param.toString()); }
From source file:org.tamilunicodeconverter.Main.java
public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // source file System.out.println("Enter the source file or directory: "); String sourceFilePath = keyboard.next(); // output dir System.out.println("Enter the output directory: "); String outputDir = keyboard.next(); // auto create file names System.out.println("Automatically create output file names based on content? (True|False): "); boolean createOutputFileName = keyboard.nextBoolean(); if (StringUtils.isNotBlank(sourceFilePath) && StringUtils.isNotBlank(outputDir)) { new TamilUnicodeConverter(createOutputFileName).convert(new File(sourceFilePath), new File(outputDir)); } else {//from w ww. ja va 2 s . c o m System.out.println("Both source and output dir are mandatory. Please run the program again."); } }