Results 1 to 7 of 7
  1. #1
    harmanbrar is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default having issue with a loops problem...

    I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:
    24-hour Clock 12-hour Clock
    -----------------------------
    00:00 0:00 a.m.
    00:15 0:15 a.m.
    00:30 0:30 a.m.
    00:45 0:45 a.m.
    01:00 1:00 a.m.
    01:15 1:15 a.m.
    01:30 1:30 a.m.
    01:45 1:45 a.m.
    02:00 2:00 a.m.


    ect...

    but cant seem to create the program and my program doesnt seem to run.
    Help would be appreciated please and thankyou.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: having issue with a loops problem...

    You seem to be missing your code! I don't know why your program doesn't work, I can't see it.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    harmanbrar is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: having issue with a loops problem...

    Quote Originally Posted by Dark View Post
    You seem to be missing your code! I don't know why your program doesn't work, I can't see it.
    sorry this is my code... it just loops over and over again...

    /**
    * Auto Generated Java Class.
    */
    public class Time {


    public static void main(String[] args) {
    String heading1 = "24-hour Clock ";
    String heading2 = "12-hour Clock";

    System.out.printf( "%-15s %15s %n", heading1, heading2);
    System.out.println("-----------------------------");

    for (int j = 0; j <= 45; j+=15){
    for (int i = 00; i <= 12; i++){
    for (int y = 0; y <= 45; y+=15){
    for (int x = 00; x <= 24; x++){
    System.out.printf( "%-15s %15s %n", i, j, x, y);

    }

    /* ADD YOUR CODE HERE */
    }
    }
    }
    }}

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: having issue with a loops problem...

    it just loops over and over again...
    With the nested loops, it would loop: (45/15)*12*(45/15)*24 times.

    How many lines did you want to print? Why not make one loop that loops that many times?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    harmanbrar is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: having issue with a loops problem...

    Quote Originally Posted by Norm View Post
    With the nested loops, it would loop: (45/15)*12*(45/15)*24 times.

    How many lines did you want to print? Why not make one loop that loops that many times?
    the program was suppose to loop for 24 hours in the 12 hour and 24 hour format

  6. #6
    harmanbrar is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: having issue with a loops problem...

    how would it work as one big loop for 2 different time formats side by side, would i use the System.out.print to get the formatting right?

  7. #7
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: having issue with a loops problem...

    Are you sure your loops are semantically correct? Such as, the right level of looping is being called for what you intend?

    1) for (int j = 0; j <= 45; j+=15){ //Minutes
    2) for (int i = 00; i <= 12; i++){ //12-Hours
    3) for (int y = 0; y <= 45; y+=15){ //Minutes
    4) for (int x = 00; x <= 24; x++){ //24-Hours}}}}

    So this is your loop, four lines of code define it. Which line will finish its loop first out of the stack? If you can't figure it out, try a simple program. Put two loops together and a System.out.println with a unique label. Observe the results to find your answer.

    EDIT: Also it would be immensely helpful for you to tell us what you are allowed to use to solve your problem. If this is for school, normally they do not like students solving the problems with techniques they have not been taught yet as this defeats the purpose of the exercise. So, if there are any specific requirements you are bound to, letting us in on the secret will help us to help you solve your problem faster.
    Last edited by Dark; 02-12-2014 at 04:14 AM.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. Problem with nested for loops?
    By Jar in forum New To Java
    Replies: 11
    Last Post: 01-23-2014, 05:49 AM
  2. for loops problem
    By Shien in forum New To Java
    Replies: 11
    Last Post: 12-06-2011, 10:32 PM
  3. I have a problem with my for loops
    By tangel in forum New To Java
    Replies: 0
    Last Post: 10-13-2011, 05:49 AM
  4. Loops and display problem
    By lk1001 in forum New To Java
    Replies: 6
    Last Post: 02-26-2010, 04:26 PM
  5. Problem with ordering for loops
    By ScaryJello in forum New To Java
    Replies: 3
    Last Post: 03-31-2009, 08:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •