3 Replies - 3688 Views - Last Post: 16 February 2011 - 07:12 PM Rate Topic: -----

#1 codebuzz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 75
  • Joined: 07-October 10

Terminating do..while loop using String! I need help

Posted 16 February 2011 - 05:12 PM

Hello guys,

Find below my piece of codes, I am having trouble terminating a do-..while loop using a string.


public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		ArrayList<String> hairList = new ArrayList<String>();
		String hairStyle;
		System.out.println("Enter the name of the hair styles");
        int count = 1;
        String end = "end";
		do{
		
			hairStyle = scan.nextLine();
			hairList.add(hairStyle);
			
			count++;
			
		}while(hairList!= );
        
        System.out.print("The Hair Styles ");
        for(int i=0;i<hairList.size()-1;i++) {
         
            System.out.print(hairList.get(i) + " ");


        }
	

	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Terminating do..while loop using String! I need help

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Terminating do..while loop using String! I need help

Posted 16 February 2011 - 05:18 PM

while(!hairList.equals(end));
Was This Post Helpful? 0
  • +
  • -

#3 codebuzz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 75
  • Joined: 07-October 10

Re: Terminating do..while loop using String! I need help

Posted 16 February 2011 - 05:23 PM

View Postpbl, on 16 February 2011 - 05:18 PM, said:

while(!hairList.equals(end));


Thanks while I enter the hairlist finished then I enter end to stop the loop, it doesn't stop.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Terminating do..while loop using String! I need help

Posted 16 February 2011 - 07:12 PM

Post your revised code

Sorry

while(!hairStyle.equals(end));

hairStyle not hairList... I just cut & pasted what you had started
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1