Write a Java-program count the number of divisible numbers in a given range(1-100) using do while loop ?

Write a Java-program count the number of divisible numbers in a given range(1-100) using do while loop ?

Program
public class Main
{
    public static void main(String args[])
    {
        int x=1,n=2,count=0;
        do
        {
            if(x%n==0)
            {
                count=count+1;
            }
            x++;
        }while(x<=100);
        System.out.print(count);
    }
}	

Output:

50

Using CommandLine Arguments
public class Main
{
    public static void main(String args[])
    {
        int x=1,n,count=0;
        n=Integer.parseInt(args[0]);
        do
        {
            if(x%n==0)
            {
                count=count+1;
            }
            x++;
        }while(x<=100);
        System.out.print(count);
    }
}	

Output:

50

Using Scanner Class
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        int x=1,n,count=0;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter n value : ");
        n=s.nextInt();
        do
        {
            if(x%n==0)
            {
                count=count+1;
            }
            x++;
        }while(x<=100);
        System.out.print(count);
    }
}	

Output:

Enter n value : 2
50





More Questions


80 . Write a Java-program count the number of divisible numbers in a given range(1-100) using do while loop ?
81 . Write a Java-program to print Factorial Number using do while loop ?
82 . Write a Java-program to print Factorial of upto N Numbers using do while loop ?
83 . Write a Java-program to print sum of natural numbers using do while loop ?
84 . Write a Java-program to print sum of Even numbers using do while loop ?
85 . Write a Java-program to print sum of Odd numbers using do while loop ?
86 . Write a Java-program to print sum of even or odd numbers based on the N value using do while loop ?
87 . Write a Java-program to print sum of even or odd numbers based on the N value using single do while loop ?
88 . Write a Java-program to display the Table using do while loop ?
89 . Write a Java-program to display vowels using continue statement ?
90 . Write a Java-program to display the whose values divisible by 2 and 3 Continue statement in java ?