Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8425643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:19:42+00:00 2026-06-10T04:19:42+00:00

Im working on the following question: A time by the 24-hour clock is a

  • 0

Im working on the following question:

A time by the 24-hour clock is a 4-digit number where the leftmost two
digits denote the hour (0 to 23, incl.) and the rightmost two digits
denote the minutes (0 to 59, incl.). For example, 2130 expresses
half-past nine in the evening. Write a class Time to encapsulate a
time. It should have the following instance methods:

get to read a time from the keyboard (supplied as a four-digit number
e.g. 2130). You may assume the number represents a valid time.

My code so far is:

import java.util.Scanner;
import java.io.*;

class Time {

private double hour, min;
Scanner scanner = new Scanner(System.in);

Time() {
    hour = 00;
    min = 00;
}

Time(double h, double m) {
    hour = h;
    min = m;
}

void get() {
    System.out.println("Please enter a time in 24 hour format: ");
    double x = scanner.nextDouble();
    hour = x / 100;
    min = x % 100;
    System.out.println("The time is " + hour + ":" + min);
}

public String toString() {
    return "Time: " + hour + min;
}
}

The problem I have is how to split the 4 digit input into hour and minute, all advice, tips appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:19:43+00:00Added an answer on June 10, 2026 at 4:19 am

    for an integer x with 4 digits:

    x / 100 - gives the 2 left digits
    x % 100 - gives the 2 right digits
    

    EDIT: Assuming here the heading zeros are silently omitted, since 0000 is translated to 0 as an integer, and will yield hour=0 (translated to 00), min=0 (translated to 00) – as it supposed to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working for a university project, and I have the following question: I have
I am altering the question now! I have the search working using the following:
my question is the following, which is the best way of working XML (kml)
I was asking the following question during interviewing in a company working on cloud
Is the possible for multiple UIViewControllers working at the same time? Consider the following
Illustration for my general question: Working with WPF I'm often stuck with the following
I'm currently learning algorithms in my spare time but have the following question while
I have the following question: I am working on a JQuery script that turns
I have a following question. We use log4j in our two projects, that are
This time my question is the following: I want to upload images using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.