• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anyone explain this program?  RSS feed

 
Dinushi Chathu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Str{
public static void main(String args[]){

double value1 = 10000;
float value2 = 35.0f;
String str = String.valueOf(value1);

System.out.println(str + value2);

}
}

output -- 10000.035.0
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...what part of program you couldn't comprehend?

Manish
 
Dinushi Chathu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't understand how come output as 10000.035.0
 
Roshi Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

str+value2 will concatenate String value of value2(10000.0) and value1(35.0) .

here '+' operator is overloaded . Hope it make sense to you !
 
Dinushi Chathu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Roshi,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!