Page 201 - Computer science 868 Class 12
P. 201
28 is a Perfect number
Sum of all the perfect numbers up to 75 is : 34
OUTPUT 2
Please Enter any num : 2
Sum of all the perfect numbers up to 2 is : 0
Program 4 Input a decimal number and convert it into its binary equivalent.
1 import java.util.*;
2 class deci_to_bin
3 {
4 void decToBinary(int n)
5 {
6 int[] binaryNum = new int[32];
7 int i = 0, j;
8 while(n > 0)
9 {
10 binaryNum[i] = n % 2;
11 n = n / 2;
12 i++;
13 }
14 for (j = i - 1; j >= 0; j--)
15 System.out.print(binaryNum[j]);
16 }
17 // driver program
18 void main()
19 {
20 Scanner sc=new Scanner(System.in);
21 int n;
22 System.out.println("Enter a number to be checked: ");
23 n=sc.nextInt();
24 decToBinary(n);
25 }
26 }
199
Statements and Scope 199

