Pages

get our extension

Search program

Tuesday, 16 April 2013

Java Program to Accept Different types of Input(int, byte, short, long, float, double, char, string, boolean) From Keyboard and displaying the entered values on monitor


package com.alok;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Accepting_input_from_keyword
{
public static void main(String[] args)throws IOException
{
/*Accepting Different type of Input(integer,float,double,short,
  long, byte, char, string, boolean) values from Keyboard*/

Boolean bul=false;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string:");
String str=br.readLine();
System.out.println("Enter a integer:");
int n=Integer.parseInt(br.readLine());
System.out.println("Enter float value:");
Float ft=Float.parseFloat(br.readLine());
System.out.println("Enter short value:");
Short sht=Short.parseShort(br.readLine());
System.out.println("Enter a Double value:");
Double dub=Double.parseDouble(br.readLine());
System.out.println("Enter a long value:");
long log=Long.parseLong(br.readLine());
System.out.println("Enter a Byte value:");
Byte bit=Byte.parseByte(br.readLine());
System.out.println("Enter a character:");
char ch=(char)br.read();


//Displaying values on console

                System.out.println("-------------------------");
                System.out.println("Entered Values are :");
                System.out.println("-------------------------");
System.out.println("Integer value is: "+n);
System.out.println("Float value is: "+ft);
System.out.println("Short value is: "+sht);
System.out.println("Double value is: "+dub);
System.out.println("Long value is: "+log);
System.out.println("Byte value is: "+bit);
System.out.println("Character value is: "+ch);
System.out.println("String value is: "+str);
System.out.println("Boolean value is: "+bul);

}

}

OUTPUT:-



Enter a string:
ALOK
Enter a integer:
1234
Enter float value:
12.1234567
Enter short value:
23
Enter a Double value:
32.123456789098765
Enter a long value:
1234567
Enter a Byte value:
21
Enter a character:
a
-------------------------
Entered Values are :
-------------------------
Integer value is: 1234
Float value is: 12.123457
Short value is: 23
Double value is: 32.12345678909877
Long value is: 1234567
Byte value is: 21
Character value is: a
String value is: ALOK
Boolean value is: false






1 comment: