473,461 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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.DecimalFormat;

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

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of days worked:");
numberOfDays = keyboard.nextInt();

}
}
================================================== =
Aug 25 '07 #1
5 2200
***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?

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

Expand|Select|Wrap|Line Numbers
  1.  import java.util.*;
  2. import java.text.DecimalFormat;
  3.  
  4. public class MoneyMaker
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         int numberOfDays;
  9.         double totalSalary, maximumDays, startingPay;
  10.  
  11.         Scanner keyboard = new Scanner(System.in);
  12.         System.out.println("Enter the number of days worked:");
  13.         numberOfDays = keyboard.nextInt();
  14.  
  15.     }
  16. }
================================================== =
Aug 25 '07 #2
"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.
Aug 25 '07 #3
prometheuzz
197 Expert 100+
...

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:

http://java.sun.com/docs/books/tutor...lts/while.html

The for Statement:
http://java.sun.com/docs/books/tutor...bolts/for.html

Good luck.
Aug 26 '07 #4
acoder
16,027 Expert Mod 8TB
Continued here:
http://www.thescripts.com/forum/show...24#post2776124

(closed this thread)
Moved from Javascript forum. Could you merge the threads (and delete duplicate posts). Thanks!
Aug 26 '07 #5
prometheuzz
197 Expert 100+
Moved from Javascript forum. Could you merge the threads (and delete duplicate posts). Thanks!
Done!
..............
Aug 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
3
by: zeroDoNotYeSpamtype | last post by:
(I tried to post this earlier, but it seems without success) A similar question to this has been answered many times, to whit the question applying when the index variable of a for loop is...
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: nina297 | last post by:
Good morning, How do I set up a For each loop to loop through my records in the database? My fields are topics, question and answers. I want the one topic displayed that goes with each...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: perkykoala | last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long. Using VB 2005: I need to design a multiple choice test (unfortunately, I can't...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.