write a java program to accept 5 numbers from the user and display it on the screen. (use all different data types like short,int,long,float, double)
Answers
Program :-
import java.util.Scanner; \\importing package
class d \\class declaration
{
public static void main (String args[]) \\main()method declaration
{
Scanner sc = new Scanner(System.in); \\input object creation
System.out.println("Enter a number of int data type:");
int i = sc.nextInt();
System.out.println("Enter a number of short data type:");
short s = sc.nextShort();
System.out.println("Enter a number of long data type:");
Long l = sc.nextLong();
System.out.println("Enter a number of float data type:");
float f = sc.nextFloat();
System.out.println("Enter a number of Double data type:");
double a = sc.nextDouble();
System.out.println("The number of type int is - " + i);
System.out.println("The number of type short is - " + s);
System.out.println("The number of type long is - " + l);
System.out.println("The number of type float is - " + f);
System.out.println("The number of type double is - " + a);
}
}
Output:-
Enter a number of int data type:
2
Enter a number of short data type:
1
Enter a number of long data type:
33
Enter a number of float data type:
4.6
Enter a number of Double data type:
3.9897978
The number of type int is - 2
The number of type short is - 1
The number of type long is - 33
The number of type float is - 4.6
The number of type double is - 3.9897978
Glossary:-
*Please see this answer from website.