- Display Even Number or Odd Number Based On The N Value Using DoWhile Loop using Single Loop
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
int x=1,n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n value");
n=s.nextInt();
do
{
if(x%2==0 && n%2==0)
{
System.out.println(x);
}
else if(x%2==0 && n%2==0)
{
System.out.println(x);
}
x++;
}while(x<=n);
}
}
output:
Enter n value
10
2
4
6
8
10
Enter n value
11
1
3
5
7
9
11
More information visit:http://sateeshm.com/
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
int x=1,n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n value");
n=s.nextInt();
do
{
if(x%2==0 && n%2==0)
{
System.out.println(x);
}
else if(x%2==0 && n%2==0)
{
System.out.println(x);
}
x++;
}while(x<=n);
}
}
output:
Enter n value
10
2
4
6
8
10
Enter n value
11
1
3
5
7
9
11
More information visit:http://sateeshm.com/
No comments:
Post a Comment