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:



Saturday, January 23, 2021

Java program to convert to binary number to decimal number.

Conversion of binary number to decimal number and its vice versa is one of the most important concept in understanding computer logics and it designs. 

Binary number is expressed in base 2. It is made up of 0s or 1s.

Example of binary number = 10101

A bit is a single binary digit. The example given above has 5 bits.

Decimal number is expressed in base 10. We can use digits from 0 to 9.

Example of decimal number = 21

Below is the program to do the conversion from Binary to Decimal:

import java.util.Scanner;
public class BinaryToDecimal 
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Binary number : ");
int binNum = sc.nextInt();
int temp = binNum;
int sum=0,i=0;
while(temp>0)
{
int rem = temp%10;
sum = sum+rem*(int)Math.pow(2,i);
temp = temp/10;
i++;
}
System.out.println("Decimal conversion of "+binNum+" = "+sum);
sc.close();
}
}



Thursday, March 21, 2019

Java Program to print HAPPY HOLI

This is for all the coding geeks who want to wish their friends in their own style.

// Java program to print Happy Holi
class Happy_holi
{   
    public static void main (String[] args)
    {
        char ch = '@';
        for (int i = 1; i <= 51; i++)
        {
            if (i == 4 || i == 7 || i == 10 || i == 11 || i == 15 || i == 16 || i == 20 ||
                i == 21 || i == 24 || i == 27 || i == 32 || i == 35 || i == 38 || i == 39 ||
                i == 42 || i == 47 || i == 48 || i == 49 || i == 50)
                System.out.print(ch);
            else
                System.out.print(" ");
        }
    
        System.out.println();
        for (int i = 1; i <= 51; i++)
        {
            if (i == 4 || i == 7 || i == 9 || i == 12 || i == 14 || i == 17 || i == 19 ||
                i == 22 || i == 24 || i == 27 || i == 32 || i == 35 || i == 37 || i == 40 ||
                i == 42 || i == 48 ||i==49)
                System.out.print(ch);
            else
                System.out.print(" ");
        }
    
          System.out.println();
        for (int i = 1; i <= 51; i++)
        {
            if (i == 4 || i == 5 || i == 6 || i == 7 || i == 9 || i == 10 || i == 11 || i == 12 ||
                i == 14 || i == 15 || i == 16 || i == 19 || i == 20 || i == 21  || i == 25 ||
                i == 26 || i == 32 || i == 33 || i == 34 || i == 35 || i == 37 || i == 40 ||
                i == 42 || i == 48 ||i==49)
                System.out.print(ch);
            else
                System.out.print(" ");
        }
    
        System.out.println();
        for (int i = 1; i <= 51; i++)
        {
            if (i == 4 || i == 7 || i == 9 || i == 12 || i == 14 || i == 19 || i == 25 || i == 26 ||
                i == 32 || i == 35 || i == 37 || i == 40 || i == 42 || i == 48 || i == 49 )
                System.out.print(ch);
            else
                System.out.print(" ");
        }
    
        System.out.println();
        for (int i = 1; i <= 51; i++)
        {
            if (i == 4 || i == 7 || i == 9 || i == 12 || i == 14 || i == 19 || i == 25 || i == 26 ||
                i == 32 || i == 35 || i == 38 || i == 39 || i == 42 || i == 43 || i == 44 || i == 45 ||
                i == 47 || i == 48 || i == 49 || i == 50)
                System.out.print(ch);
            else
                System.out.print(" ");
        }
    }
}

Output:

Wednesday, March 20, 2019

Important tips for a Happy Life

This blog is to inspire you people about life. Say goodbye to all your worries.


We all have some goals in our lives. A very few of us are able to fulfill and many of us are still dreaming for them to come true. What is there in those few people that they are able to fulfill their goals. That extra thing is Courage, Discipline and Hard Work. One cannot live complete life with no goals. Watching TV series, eating you favorite food and sleeping 10 hours a day looks fine for a day, 3 days, a week, enough! This can make someone carry unnecessary burden on mind. Also due to lack of social circle, many people fall under depression and live life in despair. Is watching TV series, eating you favorite food and sleeping 10 hours a day really worth? Will that be making any difference in life? No absolutely not. You need to get up and work for your goals. Your goals need that extra pain, extra courage and extra discipline

In today's life, people worry too much. But in reality that worry is not the worth. Constantly worrying causes depression, irritation, frustration, and bad mental health. 

I have adapted to the following 3 steps to stay away from these:
Step 1: Think about the worst possible outcome of the present situation.
Step 2: Do accept it.
Step 3: Look for the possible actions you can do to make the outcomes less unfavorable.

Do what you Love to do. 
Don't afraid. Go and fight for your goals.
Do one work at a time.
Don't take shortcuts.
Don't try to change anyone. Change yourself world will change itself.


What matters the most is Your Happiness and Your Smile. The size of your heart and beauty of your character defines the real you in this world. 

Be Humble, Loyal and Punctual 

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...