Computer Science, asked by garvit1294, 11 months ago

write a program to print odd no. from 10 to 1 using While loop in java​

Answers

Answered by philomath27
2
class Demo
{
public static void main[String arg]
{
int n = 10;

While (n>0)
{
if ( n%2!=0)
System. out.println(n);
else
n--;
}

}
}

garvit1294: what wrong
Anonymous: and there wont be any if statement
Anonymous: no condition is correct
Anonymous: but brackets r needed... then it will be correct
philomath27: What's wrong?
Anonymous: yes
Anonymous: Now correct...since u have corrected it
Anonymous: :)
garvit1294: hey what about 1 to 10?
philomath27: Mistakes are to be corrected :)❤
Answered by Anonymous
2
class ODD
{
public static void main()
{
int n=10;
while(n>0)
{
if(n%2==1)
System.out.println(n);
n--;
}
}
}
HOPE IT HELPS!
:)
pls mark it as BRAINLIEST
:D
Similar questions