Variable declairation - Java

A simple java program to explain the variable declaration in java.
Write a console program to declare and initialize a double variable with some value such as 1234.5678. Then retrieve the integral part of the value and store it in a variable of type long, and the first four digits of the
fractional part and store them in an integer of type short. Display the value of the double variable by outputting the two values stored as integers

import java.util.Scanner;
class secondappagain
    public static void main(String args[])
        Scanner sc = new Scanner(;
        System.out.print("\nInsert a double value :: ");
        double d = sc.nextDouble();
        System.out.println("\nYou inserted :: "+d);
        int i = (int)d;
        long l = i;
        double temp = d*10000;
        short s = (short)(temp%10000);
        System.out.println("\nValue in Long :: "+l);
        System.out.println("\nValue in Short :: "+s);

Post a Comment