Count the number of divisible numbers in a given range

 Count the number of divisible numbers in a given range

Range: 1-100
Number : 2

Output: 50

import java.util.Scanner;


public class Demo {


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.println(count);

}



}



Output:

Enter n value

2

50


more programs visit http://sateeshm.com/

No comments:

Post a Comment