package conversionnarrowing;
import java.util.Scanner;
public class ConversionNarrowing {
public static void main(String[] args) {
Scanner S = new Scanner(System.in);
double d;
System.out.println("Enter a Double Value: ");
d = S.nextDouble();
///convert all
float f = (float) d;
long l = (long) f;
int i = (int) l;
short st = (short) i;
byte b = (byte) st;
System.out.println("Double: " + d);
System.out.println("Float: " + f);
System.out.println("Long: " + l);
System.out.println("Int: " + i);
System.out.println("Short: " + st);
System.out.println("Byte: " + b);
}
}
Output
Enter a double value:
3.756
Double: 3.756
Float: 3.756
Int: 3
Short: 3
Long: 3
Byte: 3
Add your comment