Results 1 to 9 of 9
- 08-07-2012, 04:06 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
- 08-07-2012, 04:11 PM #2
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: I dont understand this question...
Since you are given a specific number of repetitions (30), you probably want to use a for-loop.
Where are you supposed to be getting this data?"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-07-2012, 04:16 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
Re: I dont understand this question...
From the question, I guess the user will enter the data by using either scanner or JOptionPaneInput.. thnx for reply :)
- 08-07-2012, 05:06 PM #4
Re: I dont understand this question...
have you written any code so far?
- 08-07-2012, 05:20 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
Re: I dont understand this question...
The code (just test code) above will ask user to enter student name for 10 times if not mistaken. But the question ask to display the entered data after it's done the loop process.Java Code://Revision 1 //Get and display the names, ages and heights of 30 students. import java.util.*; public class Revision1 { static Scanner console = new Scanner(System.in); public static void main (String [] args){ int student = 1; String studentName; do { System.out.println("Please enter student name : "); studentName = console.next(); student++; //System.out.println("Student name: " +studentName); }while (student<10); System.out.println("Student name: " +studentName); } }
- 08-07-2012, 05:30 PM #6
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: I dont understand this question...
The problem seems to be that you aren't storing the data as you receive it. As of now, your code will only print the name of the 9th student. You should use a data-structure such as an array or an ArrayList in order to store the data that is inputted.
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-07-2012, 05:36 PM #7
Member
- Join Date
- Feb 2012
- Posts
- 18
- Rep Power
- 0
Re: I dont understand this question...
I see.. so that's mean I need to use array? Thank you all :)
- 08-07-2012, 06:13 PM #8
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: I dont understand this question...
You probably want to print the student's name, age, and height all in one line, right? What you could do is create a Student class and override its toString() method so that it prints the name, age, and height in a structured sentence. Or you could store the data in arrays if you like.
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 08-07-2012, 07:56 PM #9
Re: I dont understand this question...
Akirien, please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
¿Values by Reference? I dont understand...
By Daxan in forum New To JavaReplies: 3Last Post: 02-22-2012, 11:27 PM -
HELP ...DONT UNDERSTAND Error
By ask4soteria in forum New To JavaReplies: 6Last Post: 11-26-2010, 09:43 AM -
i dont understand why i cant run my program please help
By kungfu in forum New To JavaReplies: 3Last Post: 07-28-2010, 02:49 PM -
Dont understand Return Statement.
By ocean in forum New To JavaReplies: 6Last Post: 10-22-2009, 12:06 PM -
Data Files - A problem that I dont understand :D
By Exhonour in forum New To JavaReplies: 7Last Post: 01-20-2009, 05:13 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks