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

pl explain

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Q29 {
public static void main(String[] args) {
int j = 0;
Q29 test = new Q29();
try {
for (j=1 ; j < 5 ; j++)
{
j+= j;
}
int i = test.process() / (j = 5);
}
catch (Exception e) {
System.out.println(e);
System.out.println("Value of j = " + j);
}
}

int process() throws Exception {
throw new Exception("Exception Encountered");
}
}
What is the Output?
1.Prints Value of j = 2
2.Throws Arithmetic Exception.
3.Prints java.lang.Exception : Exception Encountered and Value of j = 7.
4.Prints Value of j = 10
5. Prints java.lang.Exception : Exception Encountered and Value of j = 2.
answer is 2:
can anyone explain.Thanks
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anu,
The answer should be 3.
For an explanation, please see example in JLS 15.7.1.
 
Anu Kris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry the answer is 3.thanks nain
 
Anu Kris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i still have a doubt of how value of j=7...when the loop completes the value of j is 11.Pl correct me is iam wrong
 
Anu Kris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i still have a doubt of how value of j=7...when the loop completes the value of j is 11.Pl correct me is iam wrong
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anu,
Will you tell me why you think j should be 11?
Then, we can discuss it from there. Ok?
 
Anu Kris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the value of j at the end of the for loop is 11...i thought so
 
Anu Kris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam sorry.....ignore the previous msg.....value of i=7,i got it.Thanks for the help
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic