Computer Science, asked by gitasubashini, 3 months ago

Read the given program snippet:
for(int j = 1;j<=5; j++)
{ System.out.print(j+” “ );
}
Answer the following questions:
i) How mnay times the given loop will iterate?
ii) What is the final value of j on termination of the loop?
ii) What is the output of the above loop.
no wrong answeres

Answers

Answered by Oreki
7

\text{\large\bf Given Snippet}

   \texttt{for (int j = 1; j &lt;= 5; j++) \{}\\\texttt{\hspace{1em} System.out.print(j + "  ");}\\\texttt{\}}

   \textsf{\bf Answers}

        \textsf{\textbf{I.} \: The loo\symbol{112} goes from  1 to 5 hence, 5 times.}\\\textsf{\textbf{II.} \:As the loo\symbol{112} is post incremented and the last value of \texttt{j} is 5,}\\\textsf{\hspace{1em} \: so the final value of \texttt{j} is 6.}\\\textsf{\textbf{III.} }\texttt{\hspace{0.4em} 1}\\\texttt{\hspace{2em} 2}\\\texttt{\hspace{2em} 3}\\\texttt{\hspace{2em} 4}\\\texttt{\hspace{2em} 5}

Similar questions