Computer Science, asked by jaiswalvedika240, 1 month ago

write a program to print only even numbers between 1 to 20 using do-while loop( ) in java ​

Answers

Answered by Oreki
7

\textsf{\large \textbf{Solution}}

    \texttt{public class DoWhileEven \{}\\\texttt{\hspace{1em} public static void main(String[] args) \{}\\\texttt{\hspace{2em} int i = 0;}\\\texttt{\hspace{2em} do \{}\\\texttt{\hspace{3em} if (++i \% 2 == 0)}\\\texttt{\hspace{4em} System.out.println(i);}\\\texttt{\hspace{2em} \} while (i <= 20);}\\\texttt{\hspace{1em} \}}\\\texttt{ \}}

\textsf{\large \textbf{Out\symbol{112}ut}}

    \texttt{ 2}\\\texttt{ 4}\\\texttt{ 6}\\\texttt{ .}\\\texttt{ .}\\\texttt{ .}\\\texttt{ 16}\\\texttt{ 18}\\\texttt{ 20}

Answered by aryan230816
2

Answer:

import java.util .*;

class even

{

public static void main (string args [])

{

int a;

system.out.println ( " Even Number from 1 to 20:") ;

for ( a=1 ; a<=20 ; a++)

system.out.println (a) ;

}

}

Similar questions