Saturday, January 30, 2021

Different type of numbers generally asked in Java ICSE Board exams

1. Disarium Number

2. Amicable Pair

3. Unique Number

4. BUZZ number


My only motive is to provide you most simplest and easy way to do coding. Targeted Audience ICSE 9th and 10th Class. More numbers will be added soon.........................

Question 1 : Disarium Number

Write a java program to check whether the entered number is a Disarium Number. A number is called a Disarium if sum of the digits powered with its respective positions is equal to original number itself.

For example: 175 is a Disarium number.
175 = 11+72+5= 1+49+125 = 175
Here in this program we will be using Scanner class to take the input from the user.

import java.util.Scanner;
public class Disarium 
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int num = sc.nextInt();
int temp = num, rem = 0, sum = 0;//to keep original number intact taking temp 
String s = Integer.toString(num);  
int len = s.length();  //to calculate the length of number converted to string
while(temp>0)
{
rem = temp % 10;  
sum = sum + (int)Math.pow(rem,len--);
temp =  temp/10;
}
if(sum == num) //to check whether the original number is equal to the sum
System.out.println("Disarium Number.");
else
System.out.println("Not a Disarium Number.");
}
}

Output of the code:

----------------------------------------------------------------------------------------------------------

Question 2 : Amicable Pair

Write a java program to check whether the entered pair is a Amicable Pair. Amicable pair are so related that sum of proper divisors of each is equal to other number.

Amicable numbers are:(220,284), (1184,1210), (2620,2924), (5020,5564), etc.
For Example: 220 and 284 are amicable pair.
Divisors of 220 = 1,2,4,5,10,11,20,22,44,55,110
Sum of divisors of 220 = 1+2+4+5+10+11+20+22+44+55+110  = 284
Divisors of 284 = 1,2,4,71,142
Sum of divisors of 284 = 1+2+4+71+142 = 220
Here 284 is not equal to 220. And sum of divisors is equal to other number itself.

import java.util.Scanner;
public class AmicableNumber 
{
public static void main(String args[]) 
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int num1 = sc.nextInt();
System.out.print("Enter second number: ");
int num2 = sc.nextInt();
int sumNum1 = 0, sumNum2 = 0;
for(int i=1;i<num1;i++) 
{
if (num1%i==0)
sumNum1 = sumNum1+i;
}
for(int i=1;i<num2;i++) 
{
if (num2%i==0)
sumNum2 =sumNum2+i;
}
if ((sumNum1 == num2) && (sumNum2 == num1) && (num1!=num2))
System.out.println("Amicable pair");
else
System.out.println("Not amicable pair");
}
}

Output of the code:



----------------------------------------------------------------------------------------------------------

Question 3 : Unique Number

Write a java program to check whether the entered number is a Unique Number or not. A number that does not have any duplicate digit is called Unique Number.
For example: 12345, 3456 are unique numbers.
122323, 2323 are not unique numbers.

import java.util.Scanner;
public class UniqueNumber 
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt();
boolean flag = false;
String str = Integer.toString(num);
int len = str.length();
for(int i=0;i<len-1;i++)
{
for(int j=i+1;j<len;j++)
{
if(str.charAt(i)==str.charAt(j))
{
flag = true;
break;
}
}
}
if(flag==false)
System.out.println("Unique Number");
else
System.out.println("Not Unique");
}
}
Output of the code:


----------------------------------------------------------------------------------------------------------

Question 4 : BUZZ Number

Write a java program to check whether the entered number is a BUZZ number or not. BUZZ number are those numbers whose last digit is 7 or divisible by 7.

import java.util.Scanner;
public class Buzz 
{
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int num = sc.nextInt();
if(num%7==0 || num%10==7)
System.out.println(num+" is BUZZ number.");
else
System.out.println(num+" is not BUZZ number.");
}
}
Output of the code:



No comments:

Post a Comment

Check whether the word is Special word or Palindrome word.

Special words are those words which starts and ends with the same letter.  Examples: EXISTENCE COMIC WINDOW Palindrome words are those words...