Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 3rd, 2012, 03:06 AM
ahnsa564 ahnsa564 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 ahnsa564 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 12 sec
Reputation Power: 0
Unhappy Seems so simple but my brain just won't..

Hello, I'm just another newbie in need of help.

I'm trying to write a simple while loop which will read int values each repetition. The thing is, it has to read a total of 6 int values each time, instead of one.

I'm getting a hunch that it'd be a very small alteration to the usual while loop, but I can't seem to figure it out. It has definitely got me feeling incredibly stupid.

Could you please help me?

Reply With Quote
  #2  
Old October 3rd, 2012, 04:04 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
You need to break the problem down into smaller pieces to tackle it. We all start off trying to solve everything in one go, and have to train ourselves to get out of that habit.

Your general 'while' loop is something like ...

Code:
int i = 0;
while( i < some_number_of_times ) {
   // read an int
   // do something with the int
   i++;
}


So you've two things to do inside the loop. But now, one of those things has changed from 'read an int' to 'read 6 ints'. But the thing is to think about that smaller problem separate to the while loop you've already written.

The problem 'read 6 ints' could also be interpreted as 'read an int 6 times'. Now there's a hint in there for you. Any time you have to do the same thing multiple times, you'll want a 'while' (or 'for') loop. So now you should try to write a loop that will read an int 6 times (you'll probably want to set up an array to store them, rather than a single variable like you'd use if you were only reading a single int). When you've done that, you can paste that code into the correct place in your original 'while' loop.

Hope that helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Seems so simple but my brain just won't..

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap