Tuesday, September 18

Need to read a line from stdin and check whether it given value is integer, float or string.


Coding:

/* Read input from STDIN. Print your output to STDOUT*/

import java.io.*;
import java.util.*;
public class MyCode {
   public static void main(String args[] ) throws Exception {

//Write code here
Scanner input=new Scanner(System.in);
if(input.hasNextInt())
System.out.println("This input is of type Integer.");
else if(input.hasNextFloat())
System.out.println("This input is of type Float.");
else if(input.hasNextLine())
System.out.println("This input is of type String.");
else
System.out.println("This is something else. ");

   }
}


Output:

-2580
This input is of type Integer.

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...