Need help with the code...

The program should accept two inputs from user in form of military time for example (1245). Then it should calculate and display the difference.
For some reason it displays 0's...
Please help.
Thanks.
public class TimeInterval
private int firstHour;
private int firstMin;
private int secondHour;
private int secondMin;
//Constructor
public TimeInterval(String first, String second)
String h1 = first.substring(0,1);
int h2 = Integer.parseInt(h1);
firstHour = h2;
//firstHour = Integer.parseInt(first.substring(0,1));
String m1 = second.substring(2,3);
int m2 = Integer.parseInt(m1);
firstMin = m2;
//firstMin = Integer.parseInt(second.substring(2,3));
String hh1 = first.substring(0,1);
int hh2 = Integer.parseInt(hh1);
secondHour = hh2;
//secondHour = Integer.parseInt(first.substring(0,1));
String mm1 = second.substring(2,3);
int mm2 = Integer.parseInt(mm1);
secondMin = mm2;
//secondMin = Integer.parseInt(second.substring(2,3));
//Methods
public int getHours()
int HourDifference = secondHour - firstHour;
return HourDifference;
public int getMinutes()
int MinutesDifference = secondMin - firstMin;
return MinutesDifference;
import java.util.Scanner;
public class TimeIntervalTest
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the First time now:");
String hr = scanner.next();
System.out.print("Enter the Second time now:");
String mn = scanner.next();
System.out.println(hr);
System.out.println(mn);
TimeInterval timeDifference = new TimeInterval(hr, mn);
System.out.println(timeDifference.getHours());
System.out.println(timeDifference.getMinutes());
}

I can't say I understand your code, but for a starter, I think you are misunderstanding method substring:
public class StringExample {
    public static void main(String[] args) {
        String first = "2345";
        String h1 = first.substring(0,1);
        System.out.println(h1);
}

Similar Messages

  • Urgent-Need help with the code.

    Hi gurus,
    I am trying to write a code where i am populating the ZZorg1,ZZorg2 and ZZorg3 in VBRP tableto 2LIS_13_VDITM.
    WHEN '2LIS_13_VDITM'.
    DATA: X_T_DATA Like MC13VD0ITM.
       Loop at C_T_DATA into X_T_DATA.
          Select Single ZZSORG1 into X_T_DATA-ZZSORG1
                        ZZSORG2 into X_T_DATA-ZZSORG2
                        ZZSORG3 into X_T_DATA-ZZSORG3
          FROM VBRP
          WHERE VBELN = X_T_DATA-VBELN
          AND   POSNR = X_T_DATA-POSNR.
        MODIFY C_T_DATA from X_T_DATA.
        ENDLOOP.
    I am getting the following error when running a error check.
    "ZZSORG2 INTO X_T_DATA-ZZSORG2" is not expected.Can anybody let me know what i am doing wrong as i new to ABAP.          
    Thanks in advance
    Resolved it,thanks
    Message was edited by:
            sap novice

    Resolved it

  • I need help with the Quote applet.

    Hey all,
    I need help with the Quote applet. I downloaded it and encoded it in the following html code:
    <html>
    <head>
    <title>Part 2</title>
    </head>
    <body>
    <applet      codebase="/demo/quote/classes" code="/demo/quote/JavaQuote.class"
    width="300" height="125" >
    <param      name="bgcolor"      value="ffffff">
    <param      name="bheight"      value="10">
    <param      name="bwidth"      value="10">
    <param      name="delay"      value="1000">
    <param      name="fontname"      value="TimesRoman">
    <param      name="fontsize"      value="14">
    <param      name="link"      value="http://java.sun.com/events/jibe/index.html">
    <param      name="number"      value="3">
    <param      name="quote0"      value="Living next to you is in some ways like sleeping with an elephant. No matter how friendly and even-tempered is the beast, one is affected by every twitch and grunt.|- Pierre Elliot Trudeau|000000|ffffff|7">
    <param      name="quote1"      value="Simplicity is key. Our customers need no special technology to enjoy our services. Because of Java, just about the entire world can come to PlayStar.|- PlayStar Corporation|000000|ffffff|7">
    <param      name="quote2"      value="The ubiquity of the Internet is virtually wasted without a platform which allows applications to utilize the reach of Internet to write ubiquitous applications! That's where Java comes into the picture for us.|- NetAccent|000000|ffffff|7">
    <param      name="space"      value="20">
    </applet>
    </body>
    </html>When I previewed it in Netscape Navigator, a box with a red X appeared, and this appeared in the console when I opened it:
    load: class /demo/quote/JavaQuote.class not found.
    java.lang.ClassNotFoundException: .demo.quote.JavaQuote.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: \demo\quote\JavaQuote\class.class (The system cannot find the path specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Exception in thread "Thread-4" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)What went wrong? and how can I make it run correct?
    Thanks,
    Nathan Pinno

    JavaQuote.class is not where your HTML says it is. That is at the relative URL "/demo/quote/".

  • I need help with this code error "unreachable statement"

    the error_
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errors
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    public class Tools//tool class
    private int numberOfToolItems;
    private ToolItems[] toolArray = new ToolItems[10];
    public Tools()//array of tool
    numberOfToolItems = 0;
    for(int i = 0; i < toolArray.length; i++)//for loop to create the array tools
    toolArray[i] = new ToolItems();
    }//end for loop
    }//end of array of tools
    public int search(int id)//search mehtod
    int index = 0;
    while (index < numberOfToolItems)//while and if loop search
    if(toolArray[index].getID() == id)
    return index;
    else
    index ++;
    }//en while and if loop
    return -1;
    }//end search method
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0;
    int index;
    index = search(id); <-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    }//end delete method
    public void display()//display method
    for(int i = 0; i < numberOfToolItems; i++)
    //toolArray.display(g,y,x);
    }//end display method
    public String getRecord(int i)//get record method
    // return toolArray[i].getName()+ "ID: "+toolArray[i].getID()
    }//end getrecod
    }//end class
    Edited by: ladsoftware on Oct 9, 2009 6:08 AM
    Edited by: ladsoftware on Oct 9, 2009 6:09 AM
    Edited by: ladsoftware on Oct 9, 2009 6:10 AM
    Edited by: ladsoftware on Oct 9, 2009 6:11 AM

    ladsoftware wrote:
    Subject: Re: I need help with this code error "unreachable statement"
    F:\Java\Projects\Tools.java:51: unreachable statement <-----------------------------------------------------------------------------------------------------------------THIS
    int index;
    ^
    F:\Java\Projects\Tools.java:71: missing return statement
    }//end delete method
    ^
    F:\Java\Projects\Tools.java:86: missing return statement
    }//end getrecod
    ^
    3 errorsThe compiler is telling you exactly what the problems are:
    public int insert(int id, int numberInStock, int quality, double basePrice, String nm)//insert method
    if(numberOfToolItems >= toolArray.length)
    return 0; // <<== HERE you return, so everyting in the if block after this is unreachable
    int index;
    index = search(id);  //< -----------------------------------------------------------------------------------------------------------------HERE
    if (index == -1)
    toolArray[index].assign(id,numberInStock, quality, basePrice,nm);
    numberInStock ++;
    return 1;
    }//end if index
    }//end if toolitem array
    return -1;
    }//end insert method
    public int delete(/*int id*/)//delete method
    // <<== HERE where is the return statement?
    }//end delete method
    public String getRecord(int i)//get record method
    // return toolArray.getName()+ "ID: "+toolArray[i].getID() <<== HERE you commented out the return statement
    }//end getrecod
    }//end class

  • I need help with my code..

    hi guys. as the subject says I need help with my code
    the Q for my code is :
    write a program that reads a positive integer x and calculates and prints a floating point number y if :
    y = 1 ? 1/2 + 1/3 - ? + 1/x
    and this is my code
       This program that reads a positive integer x and calculates
       and prints a floating point number y if :
                 y = 1 - 1/2 + 1/3 - ? + 1/x
       import java.util.Scanner; // program uses class Scanner
        class Sh7q2
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int i = 1; // i is to control the loop
             int n = 2; // n is suppose to control the number sign
             int x; // a positive integer entered by the user
             int m;
             System.out.println("Enter a positive integer");
             x = input.nextInt();
             do
                m = (int) Math.pow( -1, n)/i;
                System.out.println(m);
                   n++;
                   i++;
             while ( m >= 1/x );
          } // end method main
       } // end class Sh7q2 when I compile it there is no error
    but in the run it tells me to enter a positive integer
    suppose i entered 5
    then the result is 1...
    can anyone tell me what's wrong with my code

       This program that reads a positive integer x and calculates
       and prints a floating point number y if :
                 y = 1 - 1/2 + 1/3 - ? + 1/x
       import java.util.Scanner; // program uses class Scanner
        class Sh7q2
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int i = 1; // i is to control the loop
             int n = 1; // n is suppose to control the number sign
             int x; // a positive integer entered by the user
             double m;
             int a = 1;
             double sum = 0;
             System.out.println("Enter a positive integer");
             x = input.nextInt();
             for ( i = 1; a <= x; i++)
                m =  Math.pow( -1, n+1)/i;
                sum  = sum + m;
                n++;
                a++;
             System.out.print("y = " + sum);
          } // end method main
       } // end class Sh7q2is it right :S

  • Need help with the Vibrance adjustment in Photoshop CC 2014.

    Need help with the Vibrance adjustment in Photoshop CC 2014.
    Anytime I select Vibrance to adjust the color of an image. The whole image turns Pink in the highlights when the slider is moved from "0" to - or + in value.  Can the Vibrance tool be reset to prevent this from happening? When this happens I cn not make adjustments...just turns Pink.
    Thanks,
    GD

    Thank you for your reply. 
    Yes, that does reset to “0” and the Pink does disappear.
    But as soon as I move the slider +1 or -1 or higher the image turns Pink in all of the highlights again, rather than adjusting the overall color.
    GD
    Guy Diehl  web: www.guydiehl.com | email: [email protected]

  • I need help with the iPad Remote app to connect to apple TV 2

    I need help with the iPad Remote app to connect to apple TV 2 I have the app already on my ipad and when I open it only shows my itunes library and not the small black Apple TV 2 icon! How do i fix this and i know it's something 

    Get the manual at http://manuals.info.apple.com/en_US/AppleTV_SetupGuide.pdf
     Cheers, Tom

  • I need help with the photo stream. Everytime I try to open it on my PC it says photo stream is unable and I have tried everuthing to enable it but it doesn't work. Any help, please?

    I need help with the photo stream. Everytime I try to open it on my PC it says photo stream is unable and I have tried everuthing to enable it but it doesn't work. Any help, please?

    Freezing, or crashing?
    ID on the Mac can produce reports that may (or may not) prove helpful in diagnosing the problem. I suspect this is something not directly related to InDesign, and maybe not to any of the Adobe apps directly since you seem to be having a problem in more than one. That often inidcates a problem at the system level.
    Nevertheless, it won't hurt to try to gather the reports. You'll find driections for how to generate them, and to post them on Pastebin.com (then put a link to them here) so we can see what's going on at Adobe Forums: InDesign CS5.5 Not Responding
    Do you happen to run a font manager? If so, which one, and waht version?

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Can you help with the code to publish Flash to my own domain.

    Thank you for your help, I publish the my site to my own domain, I do not use .Mac, I tested your code and ity works well on .Mac, can you help with the code to publish to my own domain.
    Thank you again

    You appear to have just collected a variety of code snippets and thrown them together, including a section of AS2 code ( gage.onRelease = function() {... )
    The suggestion I offered yesterday still stands.  You should find a tutorial regarding AS3 and the atan2 function.  Beyond that, what you show suggests this is a school assignment.  You should seek help from your fellow students and instructor if that is the case.

  • Need Help with the Clone Tool

    I need help with the clone tool, in that when I clone (let's say grass as example),  the new cloned area does NOT come out as sharp as the area selected.  It comes out much softer and somewhat blurred.  I have the opacity and flow both set at 100%.  This is very frustrating since I can not get a true clone.

    what "tip" do you have selected? where are you sampling from ( found in top option bar) ALSO make sure MODE is normal
    http://helpx.adobe.com/photoshop/using/retouching-repairing-images.html
    -janelle

  • I need Help with the dynamic link feature in CS3

    Hi I was wondering if anyone could help me with an issue I am having? I have the adobe cs3 master collection. Having watched tutorials on the dynamic link feature my version seems not to have the same options as those I have viewed. I wish to send my premiere video creation to encore using dynamic link, however when I click "file" and then "adobe dynamic link" the only options available are about "adobe after effects". I can export to encore however I am only alloowed to export one premiere sequence to one new encore file, I cannot create an encore file and import several premiere sequence into the same encore project. That means currently I can only have an encore creation with one premiere sequence in it, and I have no adobe dynamic link. Any help anyone could offer would be greatly appreciated.

    Thanks very much for that guys but my premiere media encoder only lets me export as: MPEG1, MPEG1-VCD, MPEG2, MPEG2 blu-ray, MPEG2-DVD, MPEG2-SVCD, H.264, H.264 blu-ray, Adobe Flash Video, Quicktime, Real Media, Windows Media. Are any of these formats DV AVI?
    Am I to export my videos direct to encore or save them elsewhere (e.g desktop). It seems that I cannot export sequences from different premiere projects to the same encore project.
    Sorry if any of these questions seem obvious, I am just new to premiere and keen to do things right from the off.
    Many thanks again guys.
    Date: Tue, 24 Nov 2009 19:32:47 -0700
    From: [email protected]
    To: [email protected]
    Subject: I need Help with the dynamic link feature in CS3
    Harm is correct.  For SD DVD, exporting as a DV AVI file from Pr will give you good results.  Encore's Automatic Transcoding will give you maximum quality for the available disc space.
    -Jeff
    >

  • HT4528 Hi  I need help with the volume on my phone  even on speaker i can barely hear who I am speaking with

    Hi I need help with the volume on my phone, even on speaker I can barely hear who I am speaking with . How do I make it louder /

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iPhone: Can't hear through the receiver or speakers
    http://support.apple.com/kb/ts1630
    -Griff W.

  • I am needing help with the final steps in restoring my iPod Touch 5

    I need help with the final steps in restoring my iPod

    I was told that the iPod would automatically go to restore mode when connected to wifi. It did not do that

  • I need help with the Web Application Certificate

    Greets,
    The title says it all really. I need help with the Web Application Certificate.
    I've followed the instructions from here:
    https://www.novell.com/documentation....html#b13qz9rn
    I can get as far as item 3.c
    3. Getting Your Certificate Officially Signed
    C. Select the self-signed certificate, then click File > Certification Request > Import CA Reply.
    I can get the certificate in to the Filr appliance but from there I'm stuck.
    Any help much appreciated.

    Originally Posted by bentinker
    Greets,
    The title says it all really. I need help with the Web Application Certificate.
    I've followed the instructions from here:
    https://www.novell.com/documentation....html#b13qz9rn
    I can get as far as item 3.c
    ok when you have you self signed certificate and you requested an official certificate with the corresponding CSR then you just need to go back to the digital certificates console. To import the official certificate, select the self signed certificate, then click File > Certification Request > Import CA Reply. Then a new windows pops out to select the certificate from your trusted authority from your local hard disk. Find the file (.cer worked for me) and click ok. As soon as you do this in the digital certificates console the self signed certificate will change the information that now it is officially signed. Look at the second column and you should see the name of your trusted authority under "issue from"
    I personally had a lot of issues across all platforms. Especially Firefox and Chrome for android. Needed to pack all the root cert, intermediate cert and signed cert into one file and import as CA reply. Not even sure if this is correct now. But at least it works.

Maybe you are looking for

  • label tag: DW8 sometimes generates illegal XHTML 1.0/Transitional code

    Dreamweaver 8 sometimes generates XHTML 1.0/Transitional code that violates the DTD when using the <label> tag for adjacent radio buttons on a form. Consider the following example: 1) Make a new HTML page using the XHTML 1.0/Transitional document typ

  • My apple id and password doe not work on icloud

    My apple id and password works fine on everything else i do!!!! but it wont let me sign into i cloud!!!!! very ****** off!!! please help

  • Report Preview Popup

    I'm trying to create a report preview where the user can click on a small icon next to the text link and popup a window with a report preview. I've got an image upload and copy to my own table process as well as a working display image process. Now I

  • JS Scripts not working in CS3

    When I was using CS2 2 years ago I was asked to make a calendar for a client. I used a script from Adobe Exchange. I have been asked to do the same this year. I am now running CS3... however this is the first time I have used my scripting panel since

  • CCMS Agent for business Connector 4.7

    HI, I want to installed CCMSR agent on BusinessConnector 4.7 to maintain alerts. is it possible to install on Business Connector as it is not like XI. If anyone got any ideas please let me know. Thanks, Chander