Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help, 2 hours before exam

Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
maybe I'm just stressed or something, but my answer is t=6, but the correct answer is apparently t=4, could someone go through this please.
Not long now, and I'm getting stuck on simple questions........not a good sign!
Any help would be much appreciated!
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as i can see, all you need to be concerned with is t. And as the for loop loops 4 times then its the same as saying for (int p=1;i<5;i++) t++;
Good luck with the exam hope i helped
It's a tiny ad only because the water is so cold.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic