Computer Science, asked by bankarpalak620, 2 months ago

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

Answered by deepakkumar9254
4

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:-

\begin{array}{| c | c | c |}\cline{1-3} \bf Variable & \bf Type & \bf Description \\ \cline{1-3} i &\sf int & to\:\:store\:\:no.\:\:of\:\:data\:\:type\:\:int \\ \cline{1-3} s &\sf short & to\:\:store\:\:no.\:\:of\:\:data\:\:type\:\:short  \\ \cline{1-3} l &\sf long & to\:\:store\:\:no.\:\:of\:\:data\:\:type\:\:long \\ \cline{1-3} f &\sf float & to\:\:store\:\:no.\:\:of\:\:data\:\:type\:\:float \\ \cline{1-3} a &\sf double & to\:\:store\:\:no.\:\:of\:\:data\:\:type\:\:double \\ \cline{1-3}\end{array}

*Please see this answer from website.

Similar questions