meaning of percent sign in java SDK2.0

what does the percent sign in this code mean?

if(y % 2 == 1)
     system.out.println(a);
kitcoopAsked:
Who is Participating?
 
modsiwCommented:
In that case it means 'if y is an odd number'

Actually it means if y is an odd number greater than 0.

-3 % 2 = -1

if(y % 2 != 0)   is a better 'if y is an odd number' statement.
0
 
avinthmCommented:
Hi ,

y % 2 results in remainder after dividing y by 2

cheers
0
 
Sys_ProgCommented:
Hi kitcoop,
> if(y % 2 == 1)
>      system.out.println(a);

It represents a modular (Remainder) operator.

Cheers!
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
suprapto45Commented:
0
 
sciuriwareCommented:
% has the same meaning in ALL JAVA versions!

;JOOP!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
yeah and it has not been changed since C, C++ ;-)
0
 
CEHJCommented:
In that case it means 'if y is an odd number'
0
 
CEHJCommented:
Yes
0
 
modsiwCommented:
The comments by avinthm, sys_prog, suprapto45, and CEHJ contain correct answers to this question. The points should probably be reawarded or split.


Thanks much.

(also, this really wasn't worth 500pts)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.