List of usage examples for java.util Scanner next
public String next()
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 3.12345f"; Scanner scanner = new Scanner(s); // assign locale as US to recognize float numbers in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a float System.out.println(scanner.hasNextFloat()); System.out.println(scanner.next()); }// www . j ava2 s. co m scanner.close(); }
From source file:utils.ImportExport.java
public static void main(String[] args) { ApiImportExportConfiguration config = ApiImportExportConfiguration.getInstance(); // create a scanner to read the command-line input Scanner scanner = new Scanner(System.in, ImportExportConstants.CHARSET); System.out.print("Enter user name :"); config.setUsername(scanner.next()); System.out.print("Enter password : "); config.setPassword(scanner.next().toCharArray()); //setting up default configurations try {//from w w w .jav a 2 s. c om ImportExportUtils.setDefaultConfigurations(config); } catch (APIExportException e) { log.warn("Unable to set default configurations"); } //setting customized configurations setUserInputs(config); //configuring log4j properties PropertyConfigurator.configure("log4j.properties");///TODO should changed if (config.getCheckSSLCertificate()) { ImportExportUtils.setSSlCert(); } //registering the client String consumerCredentials = ""; try { consumerCredentials = ImportExportUtils.registerClient(config.getUsername(), String.valueOf(config.getPassword())); System.out.println("Consumer credential " + consumerCredentials); } catch (APIExportException e) { System.out.println("Error occurred while registering the client"); System.exit(1); } //handling single API export if (StringUtils.isBlank(config.getApiFilePath()) && StringUtils.isBlank(config.getZipFile())) { try { APIExporter.singleApiExport(consumerCredentials); } catch (APIExportException e) { log.error("Error occurred while exporting the API, API cannot be exported without valid tokens "); System.exit(1); } } else if (StringUtils.isNotBlank(config.getApiFilePath()) && StringUtils.isBlank(config.getZipFile())) { APIExporter.bulkApiExport(consumerCredentials); } //handling API import if (StringUtils.isNotBlank(config.getZipFile())) { try { APIImporter.importAPIs(config.getZipFile(), consumerCredentials); } catch (APIImportException e) { String errorMsg = "Unable to Import the APIs"; log.error(errorMsg, e); System.exit(1); } } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 1.3985"; Scanner scanner = new Scanner(s); // assign locale as US to recognize double numbers in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a double System.out.println(scanner.hasNextDouble()); System.out.println(scanner.next()); }//www . j av a2s . c o m scanner.close(); }
From source file:FileSplitter.java
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Split? [true/false]: "); boolean split = Boolean.parseBoolean(scan.next()); if (split) {//ww w .j a v a 2 s. com File file = new File("T:/Java/com/power/nb/visual/dist/visual.zip"); FileSplitter splitter = new FileSplitter(file); System.out.println("splitter.split(3): " + splitter.split(3)); } else { File file = new File("T:/Java/com/power/nb/visual/dist/visual.zip.part.0"); FileSplitter splitter = new FileSplitter(file); System.out.println("splitter.unsplit(): " + splitter.unsplit()); } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com "; Long l = 1234567890987654L;/*from ww w .j a va2 s . c om*/ s = s + l; Scanner scanner = new Scanner(s); // use US locale in order to be able to identify long in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is along System.out.println(scanner.hasNextLong()); System.out.println(scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); // use US locale in order to be able to identify shorts in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a short System.out.println(scanner.hasNextShort()); System.out.println(scanner.next()); }/*from w w w . j a va 2 s . c o m*/ scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com "; Long l = 1234567890987654L;/*from w w w . j av a 2 s.com*/ s = s + l; Scanner scanner = new Scanner(s); // use US locale in order to be able to identify long in a string scanner.useLocale(Locale.US); while (scanner.hasNext()) { // check if the scanner's next token is a long with radix 4 System.out.println(scanner.hasNextLong(4)); System.out.println(scanner.next()); } scanner.close(); }
From source file:net.jmhertlein.alphonseirc.MSTDeskEngRunner.java
public static void main(String[] args) { Scanner scan = new Scanner(System.in); loadConfig();/*from w w w . ja v a 2s . c om*/ AlphonseBot bot = new AlphonseBot(nick, pass, server, channels, maxXKCD, noVoiceNicks, masters, dadLeaveTimes); bot.setMessageDelay(500); try { bot.startConnection(); } catch (IOException | IrcException ex) { Logger.getLogger(MSTDeskEngRunner.class.getName()).log(Level.SEVERE, null, ex); } boolean quit = false; while (!quit) { String curLine = scan.nextLine(); switch (curLine) { case "exit": System.out.println("Quitting."); bot.onPreQuit(); bot.disconnect(); bot.dispose(); writeConfig(); quit = true; System.out.println("Quit'd."); break; case "msg": Scanner lineScan = new Scanner(scan.nextLine()); try { bot.sendMessage(lineScan.next(), lineScan.nextLine()); } catch (Exception e) { System.err.println(e.getClass().toString()); System.err.println("Not enough args"); } break; default: System.out.println("Invalid command."); } } }
From source file:MainClass.java
public static void main(String args[]) { Scanner conin = new Scanner(System.in); int count = 0; double sum = 0.0; System.out.println("Enter numbers to average."); while (conin.hasNext()) { if (conin.hasNextDouble()) { sum += conin.nextDouble();/*from w w w. j a v a 2 s .com*/ count++; } else { String str = conin.next(); if (str.equals("done")) break; else { System.out.println("Data format error."); return; } } } System.out.println("Average is " + sum / count); }
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()); }// ww w . jav a 2 s . c o m // if a boolean is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); }