Computer Science, asked by anshu2051, 6 months ago

rewrite the following program segment using while loop instead of the for loop [2]

int f=1, i ;

for(i=1;i<=4;i++)

{ f*=i

}

System.out.println(+f);​

Answers

Answered by Oreki
3

\textsf{\large \textbf{Given Snippet}}

   \texttt{int f = 1, i;}\\\texttt{for (i = 1; i &lt;= 4; i++) \{}\\\texttt{\: \: f *= i;}\\\texttt{\}}}}\\\texttt{System.out.println(+f);}

\textsf{\large \textbf{Converted to While lo \hspace{-.68em} op}}

  \texttt{int f = 1, i = 1;}\\\texttt{while (i &lt;= 4) \{}\\\texttt{\: \: f *= i;}\\\texttt{\: \: i++;}\\\texttt{\}}}}\\\texttt{System.out.println(+f);}

Similar questions