Loop question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AManAfterGod
    New Member
    • Aug 2007
    • 2

    Loop question

    OK, I'm fairly new to Java and I wanted to try if I could convert an easy Microsoft Excel problem into Java but I've hit a road block. I was wondering if one of you could point me in the right direction.

    I'm trying to write that would double pay everyday for 35 numbers and show the output as...

    You were paid $.01 on Day 1. Your total salary is $.01
    You were paid $.02 on Day 2. Your total salary is $.03
    You were paid $.04 on Day 3. Your total salary is $.07

    Now, below is what I have so far. My question is: do I use a while Loop statement or an if-else Loop statement?

    =============== =============== =============== ========

    import java.util.*;
    import java.text.Decim alFormat;

    public class MoneyMaker
    {
    public static void main(String[] args)
    {
    int numberOfDays;
    double totalSalary, maximumDays, startingPay;

    Scanner keyboard = new Scanner(System. in);
    System.out.prin tln("Enter the number of days worked:");
    numberOfDays = keyboard.nextIn t();

    }
    }
    =============== =============== =============== ======
  • AManAfterGod
    New Member
    • Aug 2007
    • 2

    #2
    What Do I Do

    ***I posted in the wrong subforum. My aplogies***

    OK, I'm fairly new to Java and I wanted to try if I could convert an easy Microsoft Excel problem into Java but I've hit a road block. I was wondering if one of you could point me in the right direction.

    I'm trying to write that would double pay everyday for 35 numbers and show the output as...

    You were paid $.01 on Day 1. Your total salary is $.01
    You were paid $.02 on Day 2. Your total salary is $.03
    You were paid $.04 on Day 3. Your total salary is $.07

    Now, below is what I have so far. My question is: do I use a while Loop statement or an if-else Loop statement?

    =============== =============== =============== ========

    [CODE=java] import java.util.*;
    import java.text.Decim alFormat;

    public class MoneyMaker
    {
    public static void main(String[] args)
    {
    int numberOfDays;
    double totalSalary, maximumDays, startingPay;

    Scanner keyboard = new Scanner(System. in);
    System.out.prin tln("Enter the number of days worked:");
    numberOfDays = keyboard.nextIn t();

    }
    }[/CODE]
    =============== =============== =============== ======
    Last edited by prometheuzz; Aug 26 '07, 09:05 AM. Reason: Wrapped code tags around the code.

    Comment

    • etiainen
      New Member
      • Aug 2007
      • 40

      #3
      "Two or more, use a FOR"

      btw. if-else is not a loop, and there's no goto in java if you're counting on it.

      What you basically need to do is make an array of your employees and iterate trough it doing the stuff you wanna do (print, recalculate etc.).
      You may do it with a "while" as well as with a "for" or even "do...while ".

      Ou and yeah, this is not a java sub-forum.

      Comment

      • prometheuzz
        Recognized Expert New Member
        • Apr 2007
        • 197

        #4
        Originally posted by AManAfterGod
        ...

        Now, below is what I have so far. My question is: do I use a while Loop statement or an if-else Loop statement?
        ...
        You could use a while- or for-statement (both loop). An if-else statement does not loop.

        The while and do-while Statements:



        The for Statement:


        Good luck.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by prometheuzz
          Moved from Javascript forum. Could you merge the threads (and delete duplicate posts). Thanks!

          Comment

          • prometheuzz
            Recognized Expert New Member
            • Apr 2007
            • 197

            #6
            Originally posted by acoder
            Moved from Javascript forum. Could you merge the threads (and delete duplicate posts). Thanks!
            Done!
            ..............

            Comment

            Working...