• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

string with null value

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

What is the result?
A. null
B. zero
C. some
D. Compilation fails.

The answer to the above is "D"...
Can anyone explain me why the answer is D ??

[edit]Add code tags. CR[/edit]
[ October 01, 2008: Message edited by: Campbell Ritchie ]
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vicky M:
public static void main(String[] args) {
String str = "null";
if (str == null) {
System.out.println("null");
} else (str.length() == 0) {
System.out.println("zero");
} else {
System.out.println("some");
}
}
What is the result?
A. null
B. zero
C. some
D. Compilation fails.

The answer to the above is "D"...
Can anyone explain me why the answer is D ??



What syntax did you get wrong? Hint: it is in your conditionals.
 
Sheriff
Posts: 22256
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Vicky M",

Please read your private messages regarding an important announcement.

Thank you,

Rob


As for the answer, type this in and compile it. It will give you three errors, the first one is the line where the problem is.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we want to check more than one condition . . . [deleted. CR]
}
i hope this code will help you.


Thanks and regards,
ruban

[ October 01, 2008: Message edited by: ruban raj ]

[edit]Deleted solution. CR[/edit]
[ October 01, 2008: Message edited by: Campbell Ritchie ]
 
Marshal
Posts: 73257
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ruban Raj, thank you for the solution, but I would remind you what it says when you enter the beginners' forum

We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

It would have helped Vicky much more to have found the error herself; that way she would remember it far better.

I have felt it right to edit your post and delete the solution. Sorry if you think I have messed you around.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vicky Makhija wrote:
What is the result?
A. null
B. zero
C. some
D. Compilation fails.

The answer to the above is "D"...
Can anyone explain me why the answer is D ??

[edit]Add code tags. CR[/edit]
[ October 01, 2008: Message edited by: Campbell Ritchie ]

 
lowercase baba
Posts: 12992
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NehaJain Jain,

Please read the ENTIRE thread before you reply. Had you done so, you'd have seen Campbell's post at 9:13 a.m., stating that we prefer to HELP people find the solutions, not just hand them out.

I removed the answer from your post.
 
Campbell Ritchie
Marshal
Posts: 73257
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It wasn’t 9.13. It was 3.13pm. On 1st October.




2008, that was.

I hope it didn't take OP 4½ years to find the missing if?
 
fred rosenberger
lowercase baba
Posts: 12992
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Damn time-zones...
 
Ranch Hand
Posts: 172
Python MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Vicky,
As steve rightly pointed out "look carefully at your conditional expression", there is something amiss there
If you are unable to find it, then try to decipher the error thrown by JVM, Understanding error thrown by JVM can go a long way in understanding the syntax and other innate functions of the language
Cheers :-)
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic