0

This is my program:

import java.util.Scanner;
class Electricity_Reading
{
    public static void main()
    {
        System.out.println("\f");
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the previous reading");
        double a = sc.nextDouble();
        System.out.println("Enter the present reading");
        double b = sc.nextDouble();
        System.out.println("Enter your name");
        String name = sc.nextLine();
        double units = b - a ;
        int bill = 0;
        if (units <= 100)
        {
            bill = 0;
        }
        if (units > 100)
        {
            bill = bill + 8;
        }
        if (units > 200)
        {
            bill = bill + 6;
        }
        if (units > 400 && units < 900)
        {
            bill = bill + 4;
        }
        if (units > 500)
        {
            bill = bill + 10;
        }
        System.out.println("The consumer's name is : "+name);
        System.out.println("The previous reading is : "+a);
        System.out.println("The present reading is : "+b);
        System.out.println("The bill of the consumer is : "+bill);
    }
}

This is my output: Output

For some reason, the String name = sc.nextLine();command is skipped and I do not get a chance to enter the input. Why is this happening? How do I fix it? BTW I use BlueJ.

Bongo Man
  • 1
  • 1

0 Answers0