• iconJava Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

Counting Number in Java

Count the number of Divisible numbers in geiven Range
1 to 10 Number
1 to 100 Number
Output:    
Number   Count   Sum of individual Digits 
1     =   100  =      1
2     =   50   =      5
3     =   33   =      6
4     =   25   =      7
5     =   20   =      2
6     =   16   =      7
7     =   14   =      5
8     =   12   =      3
9     =   11   =      2
10    =   10   =      1 

Even count =7
Odd count= 3



Java Training in Andhra Pradesh and Telangna

Java Training in Andhra Pradesh and Telangna

import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		int x,y,count=0,ecount=0,ocount=0,sum=0,n;
		for(x=1;x<=10;x++)
		{
			count=0;
			for(y=1;y<=100;y++)
			{
				if(y%x==0)
				{
					count++;
					
				}
				
			}
		n=count;
		while (n != 0) 
		{
	           sum = sum + n % 10;
	           n = n / 10;
	    }
			
			System.out.println(x+" = "+count +"="+sum);
			sum=0;
			if(count%2==0)
			{
				ecount++;
			}
			else
			{
				ocount++;
			}
			
			
		}
		
	System.out.println("Even count ="+ecount);
	System.out.println("Odd count= "+ocount);
		
	}

}
                      

Output:
1     =   100  =      1
2     =   50   =      5
3     =   33   =      6
4     =   25   =      7
5     =   20   =      2
6     =   16   =      7
7     =   14   =      5
8     =   12   =      3
9     =   11   =      2
10    =   10   =      1 

Even count =7
Odd count= 3    




Improve Your Knowledge

Daily 10 Minite Reading