• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

String label?

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ans : It will print Hello twice.
Fine I agree with the output.But I just want to check whether my thinking is the same as yours.
According to me, i<10 and i++ will take the value of i to 9
Similarly j<10 and j++ will take the value of j to 9
then finally it checks(i+j >10) i.e 9+9 >10 ; hence it breaks the string and prints" hello"
but the ansswer says the output is being printed twice..
Still confused??
Sonir
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sonir,
The value of i will not go upto 9,
Case 1 : When value of i is 0 then the sum of i+j will not increase 10 as the max value of j is 9.
o/p - a hello will be printed
Case 2 : In this case also when the value is 1
o/p - a hello will be printed
Case 3 : In this iteration the value of i is 2
so the sum of i+j is more than 11, and that is the terminating condition.
HTH
Nisheeth
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone explain this line:

And this line:

I've never seen
String : for...
or
break String.
Thanks,
--Chris
[ January 10, 2002: Message edited by: Chris Graham ]
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is also a question that I have but never took the time to find out about. Does Java use labels like C/C++? What about goto?
My final question, do labels show up on the exam?

Thanks,
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What about goto?


Although goto is a reserved keyword in Java, it is not used.
Corey
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm rusty on my C/C++ so I don't know if their use in java is "like them." But java does use labels; the syntax is an identifier, followed by a colon, followed by a statement/statement block.
The label really only allows you to do two things with it, break out of it, or continue in it. You see labels mainly used in loop structures.
As for goto, what's that???
In java, goto is a reserved word. The language imlementors decided to make it reserved as a convenience for java compilers that might end up parsing C code and be able to "identify" that word, because it can be common in C/C++ source code. But the java language itself does not implement the use of goto.
So for the test, just remember that goto is a reserved word, but it's not used.
Rob
[ January 10, 2002: Message edited by: Rob Ross ]
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic