2 Replies - 207 Views - Last Post: 07 October 2012 - 11:26 AM Rate Topic: -----

#1 BrendanH  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 174
  • Joined: 05-May 12

string concatenation

Posted 07 October 2012 - 10:00 AM

public class GuessAnimal {
	public static void main(String[] args) {
		String animal = "unknown";
		int weight = 700;
		char sex = 'm';
		double colorWaveLength = 1.630;
		if(weight >= 500) { animal = "elephant"; }
		if(colorWaveLength > 1.621) { animal = "gray " + animal;}
		if (sex <= 'f'){animal = "female " + animal;}
		System.out.println("The animal is a " + animal);
	}
	
}



The above code is an example from a book and i wanted to know why does colorWaveLength print before weight?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: string concatenation

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: string concatenation

Posted 07 October 2012 - 10:03 AM

if animal is currently elephant the following line

animal = "gray " + animal


is really meaning

animal = "gray " + "elephant";


which results in "gray elephant".

Is that what your problem was with?
Was This Post Helpful? 1
  • +
  • -

#3 BrendanH  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 174
  • Joined: 05-May 12

Re: string concatenation

Posted 07 October 2012 - 11:26 AM

Only after i read what you put up did i realize i made an error when reading the code.

Thanks for the help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1