List of usage examples for java.util Scanner next
public String next()
From source file:isc_415_practica_1.ISC_415_Practica_1.java
/** * @param args the command line arguments */// ww w.j a v a2 s .c o m public static void main(String[] args) { String urlString; Scanner input = new Scanner(System.in); Document doc; try { urlString = input.next(); if (urlString.equals("servlet")) { urlString = "http://localhost:8084/ISC_415_Practica1_Servlet/client"; } urlString = urlString.contains("http://") || urlString.contains("https://") ? urlString : "http://" + urlString; doc = Jsoup.connect(urlString).get(); } catch (Exception ex) { System.out.println("El URL ingresado no es valido."); return; } ArrayList<NameValuePair> formInputParams; formInputParams = new ArrayList<>(); String[] plainTextDoc = new TextNode(doc.html(), "").getWholeText().split("\n"); System.out.println(String.format("Nmero de lineas del documento: %d", plainTextDoc.length)); System.out.println(String.format("Nmero de p tags: %d", doc.select("p").size())); System.out.println(String.format("Nmero de img tags: %d", doc.select("img").size())); System.out.println(String.format("Nmero de form tags: %d", doc.select("form").size())); Integer index = 1; ArrayList<NameValuePair> urlParameters = new ArrayList<>(); for (Element e : doc.select("form")) { System.out.println(String.format("Form %d: Nmero de Input tags %d", index, e.select("input").size())); System.out.println(e.select("input")); for (Element formInput : e.select("input")) { if (formInput.attr("id") != null && formInput.attr("id") != "") { urlParameters.add(new BasicNameValuePair(formInput.attr("id"), "PRACTICA1")); } else if (formInput.attr("name") != null && formInput.attr("name") != "") { urlParameters.add(new BasicNameValuePair(formInput.attr("name"), "PRACTICA1")); } } index++; } if (!urlParameters.isEmpty()) { try { CloseableHttpClient httpclient = HttpClients.createDefault(); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, Consts.UTF_8); HttpPost httpPost = new HttpPost(urlString); httpPost.setHeader("User-Agent", USER_AGENT); httpPost.setEntity(entity); HttpResponse response = httpclient.execute(httpPost); System.out.println(response.getStatusLine()); } catch (IOException ex) { Logger.getLogger(ISC_415_Practica_1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.wise.WISE.java
/** * @param args/* w w w .j a v a 2 s.c o m*/ */ public static void main(String[] args) { System.out.println("\n*** WISE Setup ***\n"); try { int mainMenuOptionSelected = mainMenuPrompt(); switch (mainMenuOptionSelected) { case 0: while (true) { System.out.println( "\nThis will wipe out all WISE data and reset to initial state. Continue? [y/n]:"); Scanner reader = new Scanner(System.in); String input = reader.next(); if (input.equals("y")) { System.out.println("Deleting any existing data and reverting to initial state..."); resetDB(springConfigClassname); resetCurriculum(); System.out.println("WISE has been reset to initial state. Exiting WISE Setup..."); break; } else if (input.equals("n")) { System.out.println("Data will NOT be deleted. Exiting WISE Setup..."); break; } else { continue; } } break; case 1: System.out.println("Exiting WISE Setup..."); break; default: System.out.println("Invalid input. Exiting WISE Setup..."); } } catch (Exception all) { System.err.println(all.getLocalizedMessage()); all.printStackTrace(System.out); System.exit(2); } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // check if the scanner's next token is a BigDecimal System.out.println(scanner.hasNextBigDecimal()); System.out.println(scanner.next()); }//w w w. j a 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"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // check if the scanner's next token is a byte with radix 4 System.out.println(scanner.hasNextByte(4)); System.out.println(scanner.next()); }/*from ww w . j a v a2s .c om*/ 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); while (scanner.hasNext()) { // check if the scanner's next token is an int with a radix of 4 System.out.println(scanner.hasNextInt(4)); System.out.println(scanner.next()); }// ww w . j a va2s . co m scanner.close(); }
From source file:Calculator.java
public static void main(String[] args) { System.out.println("type something like: 1+3"); Scanner scanner = new Scanner(System.in); double n1 = Double.NaN; double n2 = Double.NaN; String operation = null;//ww w. j a va 2 s. co m try { n1 = scanner.nextDouble(); operation = scanner.next(); n2 = scanner.nextDouble(); double result = calculate(n1, n2, operation); System.out.printf("%s %s %s = %.2f%n", n1, operation, n2, result); } catch (Exception e) { System.out.println("An invalid expression."); } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // check if the scanner's next token is a BigInteger with radix 5 System.out.println(scanner.hasNextBigInteger(4)); System.out.println(scanner.next()); }/*from www . ja va2 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 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { if (scanner.hasNextShort()) { System.out.println("Found :" + scanner.nextShort()); }/*from w w w . j a va 2 s .com*/ System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { if (scanner.hasNextInt()) { System.out.println("Found :" + scanner.nextInt()); }// www . ja v a2s . c om System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { if (scanner.hasNextShort()) { System.out.println("Found :" + scanner.nextShort(4)); }//w w w . j a v a2 s . com System.out.println("Not Found :" + scanner.next()); } scanner.close(); }