Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Akirien

Thread: I dont understand this question...

  1. #1
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default I dont understand this question...

    Hello there.... I am new to Java. This question is about repetition control.

    i. Get and display the names, ages, and heights of 30 students.

    I am a little bit confuse in which loop to be used..

    Thank you.. :)

  2. #2
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default 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

  3. #3
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default 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 :)
    awinston likes this.

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: I dont understand this question...

    have you written any code so far?

  5. #5
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default Re: I dont understand this question...

    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);
    	}
    }
    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.

  6. #6
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default 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

  7. #7
    Akirien is offline Member
    Join Date
    Feb 2012
    Posts
    18
    Rep Power
    0

    Default Re: I dont understand this question...

    I see.. so that's mean I need to use array? Thank you all :)

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: I dont understand this question...

    Quote Originally Posted by Akirien View Post
    I see.. so that's mean I need to use array? Thank you all :)
    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

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: I dont understand this question...

    Akirien, please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. ¿Values by Reference? I dont understand...
    By Daxan in forum New To Java
    Replies: 3
    Last Post: 02-22-2012, 11:27 PM
  2. HELP ...DONT UNDERSTAND Error
    By ask4soteria in forum New To Java
    Replies: 6
    Last Post: 11-26-2010, 09:43 AM
  3. Replies: 3
    Last Post: 07-28-2010, 02:49 PM
  4. Dont understand Return Statement.
    By ocean in forum New To Java
    Replies: 6
    Last Post: 10-22-2009, 12:06 PM
  5. Data Files - A problem that I dont understand :D
    By Exhonour in forum New To Java
    Replies: 7
    Last Post: 01-20-2009, 05:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •