ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2016 ICSE Computer Science Paper



Share with a Friend

Solved 2016 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Niven Number Program - ICSE 2016 Computer Science

Write a program to accept a number and check and display whether it is a Niven number or not.

Niven number is that number which is divisible by its sum of digits.

Example:
Consider the number 126.
Sum of its digits is 1 + 2 + 6 = 9, and 126 is divisible by 9.

import java.util.Scanner; class Niven{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the number: "); int n = Integer.parseInt(in.nextLine()); int sum = 0; for(int i = n; i != 0; i /= 10) sum += i % 10; if(n % sum == 0) System.out.println("Niven number"); else System.out.println("Not a Niven number"); } }

Output

 
 OUTPUT : 
Enter the number: 126
Niven number