Let us create a program to understand the importance and utilization of Ttyoken Checking Functions.The program will ask the user to enter some text(tokens).Further,the program will use the hasNextFloat() function to check every token and decide whether it can be scanned as a float value or not.It the value can be scanned as a float,it will display the token.The function will display all the tokens until it finds a token that cannot be scanned as float.

import java.util.Scanner;
public class chectype
{
    public static void main(String args[])
	{
	    Scanner objs=new Scanner(System.in);
		System.out.printIn("Enter some text");
		int num=1;
		while(objs.hasNextFloat()==true)
		{
		   float ftoken=objs.nextFloat();
		   System.out.printIn(num+")"+ftoken);
		   num++;
		}
	}
}
Show Buttons
Hide Buttons