Code example for Scanner

Methods: nextLong

        long fractNum, fractDenom;
        double fractDeci;
// Ask User To Input Numerator And Denominator Of Fraction 
        Scanner reader = new Scanner(;
        System.out.print("What is the decimal equivalent of your fraction?");
        System.out.print("\n\nEnter the numerator:  ");
        fractNum = reader.nextLong();
        System.out.print("Enter the denominator:  ");
        fractDenom = reader.nextLong();
// Convert long variables to double 
        fractDeci = (double) fractNum / (double) fractDenom;
// Show the decimal equivalent of the fraction entered 
        System.out.println("\nThe decimal equivalent of the fraction you entered is: " + fractDeci + "\n");