List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:Main.java
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Username: "); String username = scanner.nextLine(); System.out.print("Password: "); String password = scanner.nextLine(); System.out.print("What is 2 + 2: "); int result = scanner.nextInt(); if (username.equals("admin") && password.equals("secret") && result == 4) { System.out.println("Welcome"); } else {//from w w w . j ava2s.c om System.out.println("Invalid username or password!"); } }
From source file:SocketTest.java
public static void main(String[] args) { try {//from w ww. j a v a 2 s . c o m Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13); try { InputStream inStream = s.getInputStream(); Scanner in = new Scanner(inStream); while (in.hasNextLine()) { String line = in.nextLine(); System.out.println(line); } } finally { s.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(FileSystems.getDefault().getPath("logs", "access.log"), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); scanner.close();//from w w w . j a v a 2s .co m }
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel(), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); // change the radix of the scanner scanner.useRadix(32);//from ww w . j av a 2s .c om // display the new radix System.out.println(scanner.radix()); 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); // skip the word that matches the pattern .com scanner.skip(Pattern.compile(".com")); System.out.println(scanner.nextLine()); scanner.close();//from ww w . j a v a 2 s . c o m }
From source file:com.chargebee.Application.DateFormat.java
public static void main(String[] args) throws IOException, Exception { Scanner sc = new Scanner(System.in); System.out.println("Input CSV File: "); String source = sc.nextLine(); System.out.println("Input JSON File: "); String requirements = sc.nextLine(); System.out.println("Output CSV File: "); String output = sc.nextLine(); DateFormat df = new DateFormat(); JSONObject jobj = MethodBank.readJsonObjectData(requirements); CSVParser parser = MethodBank.parserInitializer(source); CSVPrinter printer = MethodBank.printerInitializer(output); df.formatter(parser, printer, jobj); parser.close();/*from ww w .j av a2s. co m*/ printer.close(); }
From source file:com.chargebee.Application.Amountediting.java
public static void main(String[] args) throws IOException, Exception { Scanner sc = new Scanner(System.in); System.out.println("Input CSV File: "); String source = sc.nextLine(); System.out.println("Input JSON File: "); String requirements = sc.nextLine(); System.out.println("Output CSV File: "); String output = sc.nextLine(); Amountediting ae = new Amountediting(); JSONObject jobj = MethodBank.readJsonObjectData(requirements); CSVParser parser = MethodBank.parserInitializer(source); CSVPrinter printer = MethodBank.printerInitializer(output); ae.formatter(parser, printer, jobj); parser.close();// www . j a v a 2 s.c o m printer.close(); }
From source file:examples.cidr.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.3/31"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();/*from w ww. j a v a 2 s.c o m*/ System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount())); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:examples.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.1/29"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();//from ww w. j a va 2 s. com System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount()); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
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 a string "com" System.out.println(scanner.findInLine("com")); // print the rest of the string System.out.println(scanner.nextLine()); scanner.close();/* ww w . j a v a2s .com*/ }