Demonstrate findInLine() : Scanner « Development Class « Java






Demonstrate findInLine()

 
/**
 *Output:
28
 */

import java.util.Scanner;

public class MainClass {
  public static void main(String args[]) {
    String instr = "Name: Joe Age: 28 ID: 77";

    Scanner conin = new Scanner(instr);

    conin.findInLine("Age:"); // find Age

    if (conin.hasNext())
      System.out.println(conin.next());
    else
      System.out.println("Error!");

  }
}

           
         
  








Related examples in the same category

1.Read int by using Scanner Class
2.Use Scanner to read user input
3.Count all vowels inputed from keyboard
4.Use Scanner to compute an average of the values
5.Use Scanner to compute an average of the values in a file
6.Use Scanner to read various types of data from a file
7.Use Scanner to compute an average a list of comma-separated values
8.use Scanner to read input that contains several different types of data
9.Letting the user decide when to quit
10.Test the input string in the while condition.
11.This program demonstrates console input.
12.Reading double value from console with ScannerReading double value from console with Scanner