Hi! I'm trying to have the user input the number of hours, minutes, and seconds, and it output what that is in seconds.

WHY WONT IT COMPILE... It says i have an illegal start of expresion at private static double hour(). help?

import java.util.Scanner;
    public class timeTest
    {
        public static void main (String[] args)
        {
            System.out.println("So I downloaded BlueJ at home!");
            System.out.println("This code is 2.6 on page 120.");
            Scanner scan = new Scanner(System.in);
            {
                private static double hour()
                {
                    double hour = 0;
                    Scanner hourScan = new Scanner(System.in);
                    System.out.println("Enter the number of hours: ");
                    double x = hourScan.nextDouble();
                    hourSec = x*3600;
                    return hourSec;
                }
                 private static double minute()
                {
                    double minute = 0;
                    Scanner minScan = new Scanner(System.in);
                    System.out.println("Enter the number of minutes: ");
                    double y = minScan.nextDouble();
                    minSec = y*60;
                 
                    return minuteSec;
                }
                 private static double second()
                {
                    double second = 0;
                    Scanner secScan = new Scanner(System.in);
                    System.out.println("Enter the number of seconds: ");
                    double z = secScan.nextDouble();
                    Sec = z*1;
                    return Sec;
                }  
            }
                System.out.println(hourSec+minuteSec+Sec);
        }
    }

Recommended Answers

All 2 Replies

Check that your {}s are paired correctly.

Member Avatar for hfx642

1. You have a method called hour(), AND you have a variable called hour.
2. You have a method called minute(), AND you have a variable called minute.
3. You have a method called second(), AND you have a variable called second.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.