Results 1 to 6 of 6
Thread: while loop
- 03-28-2011, 08:14 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
- 03-28-2011, 08:30 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Post what you've done, where your problems are and what specific issues you are having. We're not a code service, but can help you along the way with specific problems.
- 03-28-2011, 09:03 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
public static void main(String[] args) {
// print the first & last number from the list
//{5,6,-2,-10,100,7}
int num,w;
Scanner keyboard=new Scanner(System.in);
System.out.println("enter the numbers from the list");
w=1;
while(w>=6)
{
num=keyboard.nextInt();
w++;
}
}
}
this is what i got so far
i don't know what do i need to print out the first and the last number from the list
- 03-28-2011, 09:09 PM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
When you are taking inputs using scanner,put them on a array list.then just print the array[0] and array[arraylength-1]
Simple..
See,this should work.Please read your book before posting this type of easy problem which can be solved by a newer easily.Java Code:<moderator edit: code deleted>
Regards
UjjalLast edited by Fubarable; 03-29-2011 at 01:19 AM. Reason: deleted spoon-fed answer
- 03-28-2011, 10:09 PM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
...and a great example of spoonfeeding
-
Similar Threads
-
JTextField loop 2x for-loop WEIRD!
By Streetproject in forum AWT / SwingReplies: 2Last Post: 02-16-2011, 05:46 PM -
[Q] Loop issue (while loop)
By iriscience in forum New To JavaReplies: 9Last Post: 01-31-2011, 04:21 PM -
Convert do while loop to for loop
By sandeeptheviper in forum New To JavaReplies: 3Last Post: 01-03-2011, 12:37 PM -
How can I rewrite the following while loop using a for loop?
By gt11990 in forum New To JavaReplies: 5Last Post: 04-30-2010, 05:05 PM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks