Monday, January 5, 2026

Java program to print the Fibonacci Series.

 import java.util.Scanner;

class FibonacciSeries

{

static void fibonacciSeries()

{

float term1=1, term2=1, nextTerm, length;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the length of the Fibonacci Series you want : ");

length = sc.nextInt();

System.out.print("The Fibonacci series is: 1,1");

while(length-->0)

{

nextTerm = term1 + term2;

term1=term2;

term2=nextTerm;

System.out.print(","+nextTerm);

}

}

public static void main(String[] args)

{

fibonacciSeries();

}


}


Output:




Find the area of a rhombus whose side is 5 cm and whose altitude is 4.8 cm. If one of its diagonals is 8 cm long find the length of the other diagonal.

A rhombus is a parallelogram in which all the four sides are equal. In the given question, we need to find the area of a rhombus whose side is 5 cm and altitude is 4.8 cm. After we calculate the area, we can find the length of the other diagonal.

Answer: The area of the rhombus with side 5 cm and altitude 4.8 cm is 24 cm2, and the length of the other diagonal is 6 cm.

Let us draw the diagram of rhombus ABCD, then find the area and the length of the other diagonal.

Explanation:

Observe the following figure of rhombus ABCD and the dimensions that are given in the question.

rhombus ABCD

Side of the rhombus = 5 cm

So, AB = BC = CD = DA = 5 cm (Since all the sides of a rhombus are equal)

Area of a rhombus = Base × Height (Since rhombus is also a parallelogram)

= 5 cm × 4.8 cm (Since the altitude = 4.8 cm)

= 24 cm2

Now, we can find the length of the second diagonal using the following formula.

Area of a rhombus = (Product of the diagonals)/2

Here, the length of one diagonal = d1 = 8 cm and we need to find the length of the other diagonal CA = d2. We know that the area of the rhombus is 24 cm2. So, let us substitute the given values of diagonal 1 and the area in the formula.

Area of a rhombus = (d1 × d2)/2

⇒ (d1 × d2)/2 = 24

⇒ 8 × d2 = 48

⇒ d2 = 48/8

⇒ d2 = 6

Therefore, the length of the second diagonal, AC = 6 cm.

Thus, the area of the rhombus with side 5 cm and altitude 4.8 cm is 24 cm2, and the length of the other diagonal is 6 cm.

Properties of the Diagonals of Rhombus

 

Diagonal of Rhombus

The diagonal of a rhombus is a line segment that joins any two non-adjacent vertices of a rhombus. A rhombus has two diagonals that bisect each other at right angles, thus, they form 4 right-angled triangles which are congruent. Let us learn more about the diagonal of rhombus in this article.

What are the Diagonals of a Rhombus?

When the opposite vertices of a rhombus are joined, they form the diagonals of a rhombus. A rhombus has two diagonals that intersect each other at 90°. Observe the following rhombus to identify its diagonals and their properties listed in the following section.

Diagonals of Rhombus

Diagonal of Rhombus Properties

The diagonals of a rhombus are line segments that are drawn between the opposite vertices of the rhombus. The properties of the diagonals of rhombus are listed below.

  • The diagonals of a rhombus bisect each other at right angles.
  • The diagonals of a rhombus may not be necessarily equal.
  • The two diagonals divide the rhombus into four congruent right-angled triangles.
  • The length of the diagonals can be calculated by various methods like using the Pythagoras theorem or by using the area of the rhombus.

Diagonal of Rhombus Formula

The formula for the diagonals of a rhombus is based on the area of the diagonals and is expressed as p = (2 × Area)/q, where 'p' and 'q' are the two diagonals of the rhombus. We know that both the diagonals bisect each other at right angles and the two diagonals divide the rhombus into four congruent right-angled triangles. Now, using these properties, let us understand how the formula to find the diagonal of a rhombus is derived.

Derivation of Diagonal of Rhombus Formula

The formula for the diagonal of a rhombus is derived using the area of the rhombus. In other words, if the area and one of the diagonals are given, then the other diagonal can be calculated using the formula, p = (2 × Area)/q, where 'p' and 'q' are the two diagonals of the rhombus. The derivation of the formula can be understood if we derive the formula for the area of a rhombus. Since we know that the diagonals of a rhombus divide it into 4 congruent right-angled triangles, the area of the rhombus will be equal to the area of all the four triangles combined together. Observe the following rhombus to see the 4 congruent right-angled triangles that can be formed in it.

Diagonal of Rhombus

Mathematically, this can be represented as,

Area of rhombus = 4 × area of one triangle

Area of rhombus = 4 × (1/2 × base × height). Now, if we take the diagonals of the rhombus to be 'p' and 'q' respectively, then the base and height in this formula can be substituted as p/2 and q/2 respectively since we know that the diagonals bisect each other.

Area of rhombus = 4 × (1/2 × p/2 × q/2)

Area of rhombus = 4 × (1/8 × p × q)

Area of rhombus = 1/2 × p × q

Now, once this formula is derived, the formula for the unknown diagonal can be derived from this. For example, if the unknown diagonal is taken to be 'p', the formula will be p = (2 × Area)/q

Important Notes on Diagonal of Rhombus

  • The diagonals of rhombus bisect each other at right angles.
  • The diagonals of rhombus divide the rhombus into four congruent right-angled triangles.
  • A diagonal of a rhombus may not be equal to the other diagonal. 

Saturday, January 3, 2026

Spy number, Neon number, Buzz number and Armstrong numbers.

 Spy number

A spy number is a positive integer that holds a special property. To be a spy number, the sum of all the digits in the number must be equal to the product of all the digits. Let's break this down further.


When we talk about the sum of digits, we mean adding up each individual digit in the number. For example, if we have the number 1124, the sum of its digits would be 1 + 1 + 2 + 4 = 8.


On the other hand, the product of digits means multiplying all the digits together. Using the same example of 1124, the product of its digits would be 1 x 1 x 2 x 4 = 8.


For a number to be a spy number, the sum of its digits and the product of its digits must be equal. In our example, 1124 is indeed a spy number because both the sum and the product of its digits are 8.

Examples: 22, 123, 132, 1124.

Neon number

Neon Number is a special integer in the mathematics or programming world. This number has unique characteristics, as if you square the integer and then sum the digits of that square number it will result in the same integer. These types of numbers are rare and their unique property made it interesting to learn and study.

Example:

  • 9: 81 is the square of 9, and 9 is the total of its digits (8 + 1).
  • 0: The square of 0 is 0, and the sum of its digits is also 0.
  • 1: The square of 1 is 1, and the sum of its digits is also 1.
NOTE: There are only 3 neon numbers (0, 1, 9) in the first 1 lakh numbers tested.


Buzz number

Buzz number in Java is a number that is either divisible by 7 or ends with the digit 7.

Examples: 42, 107, 147, 207, 57.

Armstrong number

An Armstrong number (or narcissistic number) is an integer where the sum of its own digits, each raised to the power of the number of digits, equals the original number. 

Examples: 153,  370, 371, 407, 1634, 8208, 9474, 54748, 92727. 

Java program to access each letter of a string.

 //File name: StringLetters.java

//How to access each letter in a string.

import java.util.Scanner;

class StringLetters

{


public static void main(String[] args)

{

String name = "Ashutosh";

//First method. Using 'charAt()' and  'length()' methods of the String class.

for(int i =0; i < name.length(); i++)

{

System.out.println(name.charAt(i));

}

//Second Method.

//Print each letter using 'toCharArray()' method, that converts a string 

//to a char array and the 'length' property of an array.

//String[] nameStr = name.toCharArray(); Error: char[] cannot be converted to String[].

//Use character array instead.

char[] nameCharArray = name.toCharArray();

for(int i =0; i<nameCharArray.length; i++)

{

System.out.println(nameCharArray[i]);

}

}


}

Java menu-driven program to check if given number is a palindrome.

//File name: Palindrome.java


import java.util.Scanner;

class Palindrome{




static void palindrome ()

{

int originalNum;

int copyOforiginalNum=0;

int reverse_Num=0;

int digit=0;


System.out.println("Enter a number");

Scanner sc = new Scanner(System.in);

originalNum = sc.nextInt();

copyOforiginalNum = originalNum;


while(copyOforiginalNum>0)

{

digit = copyOforiginalNum%10;

reverse_Num = (reverse_Num*10) + digit;

copyOforiginalNum = copyOforiginalNum/10;

    

       }

if(originalNum == reverse_Num)

{

System.out.println("Palindrome");

}

else

{

System.out.println("Not a palindrome");

}



        }


public static void main(String[] args)

{      

                int choice = 1;

Scanner sc = new Scanner(System.in);

while(choice!=0)

{

palindrome();

System.out.println("Type 1 to continue else type 0 to exit.");

choice = sc.nextInt();

        }

    }

}

How can we build a chatting app like whatsapp that works on phone text messaging

To build a chat app like WhatsApp that runs on phone text messaging, you need to  use an SMS Gateway API, set up a backend server, and creat...