Need help with the for loop

Hello,
I hope someone can point me in the right direction for my next assignment. I am very new at Java programming. For my next assignment for class I will need expand my previous program which was a mortgage calculator. The first assignment we wrote a program to show the monthly payments of a $200,000 loan at 5.75% for 30 years. Now we have to output all 360 monthly payments with pauses in between so it doesnt scoll off the page. The calculation that we use is:
month_payments = (principle * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));
My question is how do I get the correct calculation outputed 360 times. I would like to use the "for loop" to do this. Also what is the correct way to do the pause command? I do not want someone to write the code, I just want some help to where I need to start off, I want to learn this on my own.
Thanks in advance,
DC

for (int i ; i < 10 ; i ++ ) { System.out.println("Come sail away"); }
or;
int i = 0;
while(i < 10)
    i++;
    System.out.println("Come sail away");
}

Similar Messages

  • I need help with my for loop in this array

    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    import javax.swing.JOptionPane;
    public class Runner
        public static void main (String[] args)
            String timeStr;
            int time, again, optiStr;
            Inbound[] in = new Inbound[25];
             in[0]=new Inbound ("",0,"On Time num0");
             in[1]=new Inbound ("",2,"On Time num1");
             in[2]=new Inbound ("",3,"Delayed num2");
             in[3]=new Inbound ("",4,"On Time");
             in[4]=new Inbound ("",5,"On Time");
             in[5]=new Inbound ("",6,"Canceled");
             in[6]=new Inbound ("",1,"Canceled num6");
             in[7]=new Inbound ("",8,"On Time");
             in[8]=new Inbound ("",9,"Delayed");
             in[9]=new Inbound ("",10,"On Time");
             in[10]=new Inbound ("",11,"Delayed");
             in[11]=new Inbound ("",12,"On Time");
             in[12]=new Inbound ("",13,"Delayed");
             in[13]=new Inbound ("",14,"On Time");
             in[14]=new Inbound ("",15,"On Time");
             in[15]=new Inbound ("",16,"On Time");
             in[16]=new Inbound ("",17,"Canceled");
             in[17]=new Inbound ("",18,"On Time");
             in[18]=new Inbound ("",19,"On Time");
             in[19]=new Inbound ("",20,"Canceled");
             in[20]=new Inbound ("",21,"On Time");
             in[21]=new Inbound ("",22,"Delayed");
             in[22]=new Inbound ("",23,"On Time");
             in[23]=new Inbound ("",24,"Cancled");
             in[24]=new Inbound ("",7,"On Time num24");
            do{
                timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
                time = Integer.parseInt(timeStr);
                if (time<=0 || time>24)
                 JOptionPane.showMessageDialog (null, "Error");
                 optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
                if (optiStr==JOptionPane.YES_OPTION)
    //(ok this is the for loop i am talking about )
                    for (int index = 0; index < in.length; index++)
                      if ( time == Inbound.getTime())
                   JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    //               else JOptionPane.showMessageDialog (null, "else");
                }//temp return else if failed to find time asked for
    //             else
    //               if (optiStr==JOptionPane.CANCEL_OPTION)
    //                 JOptionPane.showMessageDialog(null,"Canceled");
    //              else
    //                {Outbound.run();
    //                JOptionPane.showMessageDialog (null, "outbound");}//temp
                  again=JOptionPane.showConfirmDialog(null, "Try again?");
            while (again==JOptionPane.YES_OPTION);
    }any help would be greatly appriciated.

    rumble14 wrote:
    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    >//(ok this is the for loop i am talking about )
    for (int index = 0; index < in.length; index++)
    if ( time == Inbound.getTime())
    JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
    Edited by: darb on Mar 26, 2008 11:12 AM

  • Need help with a For loop that uses a Break statement

    I need to create a for loop which counts down from 100-50 and divides the number being counted down by a counter. Can anyone help me?
    public class Break
    public static void main ( String args []) (;
         int total = 0
         int counter = 0
         for { (int number = 100; total >=50; total --)
         if (counter == 0)
         break;
         } // end of for loop
         int output = number/counter
         system.out.printf("The number is" %d output/n)
         }// end of method main
    }// end of class Break

    Im sorry I didnt explain myself very well i do not need the break statement at all.
    I now have this code:
    public class BreakTest
       public static void main( String args[] )
          int count; // control variable also used after loop terminates
         for (int i = 100; i >= 50; i = ++count)
       if (i >= 50) {
        continue;
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
       } // end main
    } // end class BreakTest
    /code]
    and i get these error messages:
    F:\csc148>javac BreakTest.java
    BreakTest.java:9: variable count might not have been initialized
         for (int i = 100; i >= 50; i = ++count)
                                          ^
    BreakTest.java:15: variable count might not have been initialized
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
                                                                    ^
    2 errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help with a for loop

    Hi all
    I have a dir that has a list of folders that are created using php that my customers upload to. the PHP creates a new folder using the system date on the days that they upload. (using this format yyyymmdd)
    What I am trying to do is loop thou the folders and get todays folder and list the files that are in todays folder. I have been able to do this up to the point of if a customer folder does not have a folder called todays date.
    I know I need some sort of try / catch but don't know what.
    Can anyone help me please
    Thanks for you time and help in advance
    Craig
      public void getfolderList() {
        File dir = new File("/Users/craig/Documents/jBuilder_Epod/copy");
        File[] getFolderNames = dir.listFiles();
        if (getFolderNames != null) {
          for (int gf = 0; gf < getFolderNames.length; gf++) {
            String store = "" + getFolderNames[gf];
            if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
              String folderName = "" + getFolderNames[gf];
              if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
                //I need to have some sort of try and Catch here.
                // If there is no Folder called "todaysFileName" I need to go to the next folder
                //i.e. stop the for loop and go to next
                String setTodaysFileName = folderName + "/";
                String todaysFileName = setTodaysFileName + systemDate;
                File todaysFolder = new File(todaysFileName);
                File[] todaysFiles = todaysFolder.listFiles();
                for (int td = 0; td < todaysFiles.length; td++) {
                  todaysFileName = "" + todaysFiles[td];
                  System.out.println("There is no folder Today........" +
                                     todaysFileName);
      }

    A quick guess would be that after the sStatement
      File[] todaysFiles = todaysFolder.listFiles();todaysFiles is null if todaysFolder doesn't exist and you get a NullPointerException when trying to access todaysFiles.length in the following for-loop.
    If that doesn't help, please be a bit more precise what kind of Exception occurs...

  • Need help with basic "for" loops!

    Here is my prompt for class:
    Write a program that prompts the user to enter a sentence from the keyboard using JOptionPane.showInputDialog.
    The program will print the characters back with the first letter of each word changed from lower case into upper case. If you have a capital letter in the original line and it is not the first letter of a word, then this letter should be switched from upper case to lower case. The only capital letters that should appear in the line must be the beginning letter of every word in the line. All other characters will remain the same.
    I figured everything out except for one part. How do I make the first letter of each word change from lower case into uppercase? How do I switch a letter that is uppercase in the middle of a word to lowercase? Last but not least, how do I make sure that the only capital letters in the sentence are the first letter of each word?
    I need to do this using for Loops, charAt(), and if/else statements because this is just an intro class. I just can't figure this last part out! Help please!

    String words = ...;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < words.length; i++) {
    char c = words.charAt(i);
    boolean isUpper = Character.?(look up the methods in java.lang.Character)
    boolean isLetter = ? (there are actually 2 ways to do this. Hint: you can use <= and >= and && to solve this)
    if (!isLetter) {
    continue;
    } else {
    // check if this is the start of the word. How do you know that you are at the start of a word?
    if (!isUpper && isStartOfTheWord) c = Character.toUpperCase(c); //Hint: there is a way you can do this with x + y
    else if (isUpper) //make c lower case
    builder.append(c);
    return builder.toString();

  • Please help with the FOR loop and the array..

    I was trying to place some words in the Movie Clip
    "TextPanel" and set a
    random position to each of them.
    But it's not working.
    1) I created a Movie Clip "word" and inside that MC I created
    a text field
    and gave it an identifier "textFiled".
    2) The linkage name for Movie Clip "word" I set to "word".
    3) In the actionscript I created an Array called "aWords".
    4) Then I created a FOR loop that should
    place (attach) Movie Clips "word0", "word1", "word2" and
    "word3" to the
    movie clip TextPanel, and set the textField text for each of
    them to the
    text from the Array.
    But the script attaches 4 Movie Clips with a name
    "Undefined", instead of 4
    different names (from the Array).
    What is wrong with this script?
    var aWords:Array = [apple,banana,orange,mango];
    for(i=0;i<aWords.length;i++){
    var v = TextPanel.attachMovie("word","word"+i,i);
    v.textFiled.text = aWords
    v._x = randomNumber(0,Stage.width);
    v._y = randomNumber(0,Stage.height);
    Thanks in advance

    But in my Post I already wrote v.textFiled.text = aWords
    so I don't understand what were you correcting..
    And one more:
    I have tested it by changing the
    v.textFiled.text = aWords; to v.textFiled.text = "some
    word";
    and it's working fine.
    So there is something wrong with the Array element, and I
    don't know why..
    "aniebel" <[email protected]> wrote in
    message
    news:ft2d5k$lld$[email protected]..
    > Change:
    > v.textFiled.text = aWords;
    >
    > to:
    > v.textFiled.text = aWords
    >
    > It needs to know which element inside the array you want
    to place in the
    > textfield (or textfiled) :)
    >
    > If that doesn't work, double check that your instance
    name is correct
    > inside
    > of "word".
    >

  • Need help with a for loop - string checking

    I am trying to create a for loop to make sure a user entered string contains only letters but something doesn't take. No errors, but the inner loop of try again doesn't ever come into play. What am I missing please.
         String k = keyboard.nextLine();
         for (int i = 0; i < k.length(); i++)
              char c = k.charAt(i);
              int m = c; 
              if (((m < 97) && (m > 122)) || ((m < 65) && (m > 90)))
                        System.out.print("Try again please: ");
                        k = keyboard.nextLine();
    System.out.println(k);

    molested,
    (you and BigDaddyLoveHandles should get on well)
    I would use regular expression for that... which would look something like this...
    // get response containing at least one letter.
    while (true) {
      String response = keyboard.nextLine();
      if( response.matches("[a-zA-Z]+") ) break;
      System.out.print("Try again please: ");
    }Message was edited by: corlettk - frog got the {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Need help with a for loop please

    Hello,
    I want to do the following:
    double V[][] = sphere.V2;
    double polygon[][][] = {
         { V[0], V[1], V[2] },
    { V[1], V[2], V[3] },
    { V[2], V[3], V[4] },
    { V[3], V[4], V[5] },
    { V[4], V[5], V[6] },
    { V[124], V[125], V[126] },
    How can I set up a loop to initialize the values of polygon so that I dont have to type it all out?
    Thanx a lot
    -Big_Goon

    Any suggestions?
    -Big_Goon

  • The demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.

    the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
    your recommended second option that i could add true/false case.
    this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
    loop, how can i send stop command from outer while
    loop?
    more over do you have any example for this please?
    thanks"

    You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
    Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
    Ben's response looks pretty good and detailed to me. It certa
    inly deserved better than a 1-star rating.

  • I still need help with the Dictionary for my Nokia...

    I still need help with the Dictionary for my Nokia 6680...
    Here's the error message I get when trying to open dictionary...
    "Dictionary word information missing. Install word database."
    Can someone please provide me a link the where I could download this dictionary for free?
    Thanks!
    DON'T HIT KIDS... THEY HAVE GUNS NOW.

    oops, im sorry, i didnt realised i've already submitted it
    DON'T HIT KIDS... THEY HAVE GUNS NOW.

  • 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]

  • Need help with pagination for book

    I am working on a book and need help with the pagination. I was able to make the TOC and front matter show the numbers as Roman numerals, and the body of the text as Arabic numerals, but I can't figure out how to restart the numbering sequence for the body of the text. So the front matter is numbered i-xvi, and the text is 17-681. I need the text to start with the number 1. Each subsequent chapter is a section break as well, if that makes a difference.
    Many thanks,
    J

    Click on the page that shall start on number one. Open Inspector palette > Layout inspector (2nd tab) >
    Section > Start at: > 1

  • 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

  • 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/".

Maybe you are looking for

  • How to get digital signature for Google Map geocoding V3 in PL/SQL?

    Hi, Gurus:     Could anyone provide me an example about how to generate digital signature for Google Maps service v3 in PL/SQL? We tried to upgrade our program using Google maps service from v2 to v3. We are using PL/SQl on background to send request

  • Weird problem using "Login" in MaxL script

    Hi there I have created a MaxL script for loading som data into an Essbase. The script you can see below. login 'user' 'password' on 'nkm18k14'; import database 'realtest'.'Loadtest' data from text data_file '\\nkm18k00\Planning\Loaddata\lonbud.txt'

  • Removing StuffIt options from Rick Click Menu!

    I removed StuffIt via AppDelete. And I still have the options whenever I right click anywhere. How can i remove this?

  • Problem getting bundles to sub vis

    Hi, I would appreciate help telling me how to get data which I set on the main front panel to pass on to a sub vi. I have a number of inputs on my front panel, which is surrounded by a while loop. They have to go to a sub vi outside of the while loop

  • Material Master data problem

    Hello, In our scenario, there are 2 plants in one company code. We created a material in one plant and then extend the same in another plant also. Now if I am changing the material for one plant than this material is getting changed in other plant al