Results 1 to 5 of 5
  1. #1
    idreamavi is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default this code is showing wrong out put

    the below program is to read the time intervals (HH:MM) and to compare system time if the system time between your time intervals print correct time and exit else try again to repeat the same thing. By using StringToknizer class. and i have written like this
    import java.io.*;
    import java.util.*;
    public class Main
    {
    static int k1,k2,v1,v2;
    public static void main(String args[]) throws IOException
    {
    DataInputStream o=new DataInputStream(System.in);
    System.out.println("Enter minimum interval:");
    String a=(String)o.readLine();
    System.out.println("Enter maximum interval:");
    String b=(String)o.readLine();
    String c=a+";"+b;
    StringTokenizer st=new StringTokenizer(c,":;");
    while(st.hasMoreTokens())
    {
    k1=Integer.parseInt(st.nextToken());
    v1=Integer.parseInt(st.nextToken());
    k2=Integer.parseInt(st.nextToken());
    v2=Integer.parseInt(st.nextToken());
    }
    Calendar cal=Calendar.getInstance();
    int h=cal.get(Calendar.HOUR);
    int m=cal.get(Calendar.MINUTE);
    if((h>=k1)&&(m>=v1)&&(h<=k2)&&(m<=59))
    {
    System.out.println("Time: "+h+":"+m);
    }
    else
    {
    System.out.println("hi");
    }
    }
    }

    but is showing correct for some inputs and wrong for some inputs
    and ineed u people suggesstions about this tq

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    13

    Default Re: this code is showing wrong out put

    I would suggest you actually take the time and effort to specify what you consider correct output and wrong output, and to give examples of the input you feed the code.

    Right now you're just telling half the story and expect people to guess the rest.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    27

    Default Re: this code is showing wrong out put

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    idreamavi is offline Member
    Join Date
    Feb 2015
    Posts
    3
    Rep Power
    0

    Default Re: this code is showing wrong out put

    expected output:
    run1:
    Enter minimum interval:
    11:30
    Enter maximum interval:
    12:00
    let us assume the system time is 11:30
    the out put is -- Time: 11:30

    Run 2
    Enter minimum interval:
    11:36
    Enter maximum interval:
    12:00
    let us assume the system time is 11:32
    the out put should be HI because 11:32 is not in the interval but it is printing the time 11:32

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: this code is showing wrong out put

    Have you tried debugging the code? Print out the values of all the variables so you can see what the computer sees when the code is executed. The output should help you fix the problem.

    Please edit your post and wrap the code in code tags. See post#3
    Last edited by Norm; 02-24-2015 at 03:15 PM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 12-21-2013, 05:52 PM
  2. Replies: 9
    Last Post: 05-28-2013, 10:14 AM
  3. Replies: 1
    Last Post: 03-11-2013, 08:24 PM
  4. Old gui showing instead of new gui code
    By aianta in forum New To Java
    Replies: 7
    Last Post: 11-28-2011, 03:30 AM
  5. Replies: 1
    Last Post: 03-30-2010, 10:23 PM

Tags for this Thread

Posting Permissions

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