Results 1 to 5 of 5
  1. #1
    Kristy is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Problem Solve~

    Statement:

    -Use while loop or for loop

    -You are require to ask the user to enter their
    ~Annual Rate
    ~Total Investment
    ~Year Of Investment

    -Then if the user enter 0 for either 1 above, display a error message says "Error".

    -The formula is( i not sure correct anot also....):

    Investment=(rate/100*investment*year)+investment

    Here is what I had done:

    import javax.swing.JOptionPane;
    public class Haha{
    public static void main (String[] args){
    double investment=0.0,rate=0.0,year=0.0;

    rate=Double.parseDouble(JOptionPane.showInputDialo g("Please Input Your Annual"));
    investment=Double.parseDouble(JOptionPane.showInpu tDialog("Please Input Your Total Investment"));
    year=Double.parseDouble(JOptionPane.showInputDialo g("Please Input Your Year Of Investment"));

    double rate=x,investment=y,year=z;

    while if(x==0){
    System.out.println("Error");
    }else{
    y=x/100*y*z+y
    }
    }
    }

    It's worng XD can anyone help me....please?
    Last edited by Kristy; 11-18-2008 at 05:23 PM. Reason: Problem Solve~

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Did you compile and run the code? What happen if so? Copy-paste the error message here if you get any. No one here waiting to do your homework lol

  3. #3
    Kristy is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    okay...i juz figure out wat happen when i was still doing the code ....
    I can't use while if and i think i'll be using if statement..cause I really have no clue on how to used the for(int i=1;i<=n;i++) concept Thanks Again! and I'll make sure to list the error next time too XD

    Will Close this thread~

  4. #4
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    the for statement work like this

    Java Code:
    for(starting value, how long the value goes for, how to increment the value){
    //stuff that needs the value goes in here
    }

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Kristy View Post
    okay...i juz figure out wat happen when i was still doing the code ....
    I can't use while if and i think i'll be using if statement..cause I really have no clue on how to used the for(int i=1;i<=n;i++) concept Thanks Again! and I'll make sure to list the error next time too XD

    Will Close this thread~
    Did you read any document related to for loop. It's a simple thing if you read more about it.

    Read this whole page first of all.

Posting Permissions

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