Example usage for java.util Scanner nextLine

List of usage examples for java.util Scanner nextLine

Introduction

In this page you can find the example usage for java.util Scanner nextLine.

Prototype

public String nextLine() 

Source Link

Document

Advances this scanner past the current line and returns the input that was skipped.

Usage

From source file:Main.java

public static void main(String[] args) {
    Scanner scanInput = new Scanner(System.in);
    String input = scanInput.nextLine();
    System.out.println("The input is : " + input);
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Enter a string");
    Scanner input = new Scanner(System.in);
    String s1 = input.nextLine();
    s1 = s1.trim();// ww  w .  j a va 2s. com
    int howLong = s1.length();

    for (int counter = 0; counter < howLong; counter++) {
        char ch = s1.charAt(counter);
        System.out.print(ch);
    }

}

From source file:Main.java

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    String answer = input.nextLine();

    if ("yes".equals(answer)) {
        System.out.println("Yea!");
    } else {//from ww  w.  j  a v a 2  s  .  c  o m
        System.out.println("No :(");
    }
}

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);

    System.out.println(scanner.nextLine());

    System.out.println("" + scanner.toString());

    scanner.close();//from   w  w  w  .  j av  a  2s .com
}

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);

    System.out.println(scanner.nextLine());

    // attempt to call remove results in an exception
    scanner.remove();/*  w  w w.  j av  a  2  s  .com*/

    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);

    System.out.println(scanner.nextLine());

    // print the default radix
    System.out.println(scanner.radix());

    scanner.close();/*  ww  w .  ja va 2 s. com*/
}

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);

    System.out.println(scanner.nextLine());

    // change the radix of the scanner
    scanner.useRadix(32);/*from   w ww .j  av  a2  s.  c  o  m*/

    // 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);

    System.out.println(scanner.nextLine());

    // change the delimiter of this scanner
    scanner.useDelimiter("Wor");

    // display the new delimiter
    System.out.println(scanner.delimiter());

    scanner.close();// www  .  ja  v a2s .c om
}

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);

    System.out.println(scanner.nextLine());

    // change the locale of the scanner
    scanner.useLocale(Locale.ENGLISH);

    // display the new locale
    System.out.println(scanner.locale());

    scanner.close();//from ww w  .j  av  a 2  s.  c o  m
}

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);

    System.out.println(scanner.nextLine());

    // change the delimiter of this scanner
    scanner.useDelimiter(Pattern.compile(".ll."));

    // display the new delimiter
    System.out.println(scanner.delimiter());

    scanner.close();//w  ww .ja va 2s  .c  o  m
}