• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Please help me out this problem.look at last line

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

The answer is Element[1, 0]: 2
Element[2, 0]: 9
sum: 11


The question is why is [2,1] [1,2 ]is not calculated ???
please help me


( tags added, tabs by spaces and attempted to clean up formatting)
[ September 02, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Initially when I=0 and j=0 if(j==i) break; is executed and so control breaks out of the inner loop.
In the next iteration of the outter loop, we have
i=1 and j=0, this time the first if will not get exeuted and control proceeds to execute the System.out.println()

Output at this point is
Element[1, 0]: 2

And the value of sum is 2, which is less than 10, so second if is not executed

Now moving to next iteration of outter loop
i=2 and j=0, this time also the first if will not get exeuted and control proceeds to execute the System.out.println()

Output at this point is
Element[2, 0]: 9

Now sum is 9+2 =11 greater than 10, so the second if gets executed and comes out of the scope defined by the label outer:

Hope this helps :-)
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot

god bless you
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic