A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
< operator
vineet walia
Ranch Hand
Joined: Feb 16, 2008
Posts: 138
posted
Nov 18, 2009 22:04:52
0
class puzzle11 { public static void main(String str []) { int a=1, b=5; boolean c= a<b; System.out.println("direct output"+5<6); System.out.println(("%%"+ c)); } }
1st syso statement give error which is
The operator < is undefined for the argument type(s)
String
, int
but if < operator can not be operate on int then why 1st syso statement is executing ??
avi sinha
Ranch Hand
Joined: Mar 15, 2009
Posts: 452
I like...
posted
Nov 18, 2009 22:15:14
0
the reason here is the "string" before the digits you want to compare.
your line can be subdivided as : "direct output"+5<6 ---> "direct output5" < 6
and you can't compare a string with a number. you should write "direct output"+(5<6) it will work for sure.
avi sinha
SCJP 5.0 SCWCD 5.0
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 804
1
I like...
posted
Nov 23, 2009 01:51:01
0
It's only operator precedence.
SCJP6, SCWCD5, OCE:EJBD6.
BLOG:
http://leakfromjavaheap.blogspot.com
S Bhanage
Greenhorn
Joined: Oct 28, 2009
Posts: 13
posted
Nov 23, 2009 09:50:19
0
Use the following
System.out.println("direct output"+(5<6));
It works fine.
I agree. Here's the link:
http://aspose.com/file-tools
subject: < operator
Similar Threads
Want to convert my code in method
please explain its output
LinkedHashMap - trying to use the method removeEldestEntry
How to set value in jtable fields??
Simple precedence question.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter