What will the following code segment print? int i; for(i=1;i - ProProfs Discuss
Advertisement

What will the following code segment print?
int i; for(i=1;i<=4;i=i+3); System.out.println(i);

Asked by Wyatt Williams, Last updated: Apr 09, 2024

+ Answer
Request
Question menu
Vote up Vote down

1 Answer

John Smith

John Smith

John Smith
John Smith

Answered Sep 19, 2016

7

The value will be printed only when the loop is terminated. Since its a one-line loop so it wont repeat the printing statement. Loop terminated when i becomes 7. So 7 will be printed.
upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.