• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Query on operators

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the out put of this ??

class Sixties {

public static void main(String[] args) {
int x = 5;
int y = 7;

System.out.println((y*2) % x));
System.out.println("" +(y % x));

}
}
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[c]
the output is
4
2
[/c]
[d]
first of all correct your code there was an error you have not closed one of the brackets
class Sixties {

public static void main(String[] args) {
int x = 5;
int y = 7;

System.out.println((y*2) % x);
System.out.println("" +(y % x));
}
}

System.out.println((y*2) % x); // here (y*2)ie.=7*2=14%5 which will give the remainder as 4
[/d]
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a typical question to be asked.
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mary,

In the future, you should compile the code, run it and see what happens for yourself. Then tweak the code to see how your changes affect the output. This is a great way to learn.

If you want to understand why something happens, then post your question and someone will be happy to help.

Good luck.
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic