This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a question for you guys!
Is it possible we can make an array of variables?
I mean if you look at my code I tried to create an array of String which was supposed to be prompted after getting the user input.
as you can see I had to assigned all my doubles(day of week) into input.nextDouble().in this way I can get the user input correctly but the System.out.println("Your Hours for " + days[i] +":"); just print out the first line and scanner starts to tracking the inputs.
Your Hours for Tuesday:
You have worked 0.0 for Friday
now my question is how i can prompt with System.out.println("Your Hours for " + days[i] +":") after each input and how I can reduce the amount of
monday = input.nextDouble();
tuesday = input.nextDouble();
wednesday = input.nextDouble();
thursday = input.nextDouble();
friday = input.nextDouble();
saturday = input.nextDouble();
sunday = input.nextDouble();
Just like an array of Strings you can create an array of double
ex double  hoursOnDays = new double;
I have specified the size as 7 for seven days of week.
Now you can simply do something like
hoursOnDays[i] = input.nextDouble();
Just replace all the lines with this one line - the output should be as expected - One line will be printed followed by the console waiting for user input. This will run just 6 times because your for loop starts from 0 and ends when i< 6. If you want it to run 7 times, the condition should be i<7
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD