Posts

Classification of Animals

 All animals, including humans, belong to the kingdom Animalia . Animals that depend on plants and other animals for food are known as heterotrophs . The backbone is also called the  vertebral column . Animals with a backbone are called vertebrates . Animals without a backbone are called invertebrates . Invertebrates are divided into eight major phyla. Coelenterates have a radially symmetrical body. The tentacles in cnidarians have stinging cells called cnidoblasts . Earthworms are considered as a farmer's friend. Flatworms are the simplest worms or animals without legs. Annelids have special organs called nephridia for excretion. Exoskeleton is a rigid external covering of the body found in some invertebrates that provide support and protection. In arthropods, an image is formed in several pieces. This type of vision is called mosaic vision . Echinoderms have an unsegmented body. Octopus is the largest among invertebrates. Young frogs called tadpoles breathe through g...

Search Product Code in Binary File

A binary file named "ABC.DAT" contains the product code (pc), unit price (up) and quantity (q) for number of items. Write a method to accept a product code 'p' and check the availability of the product and display with an appropriate message. The method declaration is as follows: void findpro(int p) import java.io.*; import java.util.Scanner; class ReadData{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.print("Product code to be searched: ");         int p = Integer.parseInt(in.nextLine());         findpro(p);     }     public static void findpro(int p){         boolean eof = false;         boolean found = false;         try{             FileInputStream fis = new FileInputStream("ABC.DAT");           ...

Matrix Multiplication in Java

Write a Java program to perform matrix multiplication. Multiplication of two matrices is possible only if number of columns in matrix A = number of rows in matrix B. The dimensions of the resulting matrix will be: Number of rows of matrix A × Number of columns of matrix B. import java.util.Scanner; class Multiply{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.print("Rows of matrix 1: ");         int r1 = Integer.parseInt(in.nextLine());         System.out.print("Columns of matrix 1: ");         int c1 = Integer.parseInt(in.nextLine());         System.out.print("Rows of matrix 2: ");         int r2 = Integer.parseInt(in.nextLine());         System.out.print("Columns of matrix 2: ");         int c2 = Integer.parseInt(in.nextLine());   ...

Highest Row-wise and Lowest Column-wise Elements in a Matrix in Java

Write a Java program to declare a matrix a[][] of order m × n, where 'm' is the number of rows and 'n' is the number of columns such that m and n are positive integers. Accept the elements i.e. positive integers into this matrix. Now check and display the highest elements row-wise and the lowest elements column-wise. Test the program for the following data and some random data. import java.util.Scanner; class Matrix{     public static void main(String args[]){         Scanner in = new Scanner(System.in);         System.out.print("m = ");         int m = Math.abs(Integer.parseInt(in.nextLine()));         System.out.print("n = ");         int n = Math.abs(Integer.parseInt(in.nextLine()));         int a[][] = new int[m][n];         int i, j;         System.out.println("Enter matrix elements:");         ...

Unique Digit Number in Java

A unique digit number is a positive integer (without leading zeroes) with no duplicate digits. For example: 7, 135, 214 are all unique digit numbers, whereas 33, 3121, 300 are not unique digit numbers. Given two positive integers m and n, where m < n, write a Java program to determine how many unique digit numbers are there in the range between m and n (both inclusive) and display them. The input consists of two positive integers m and n where both m and n should be < 30000. You are required to display the number of unique digit numbers in the specified range along with their values in the format specified below: Test your program for the following data and some random data. Example 1: INPUT: m = 100 n = 120 OUTPUT: THE UNIQUE DIGIT NUMBERS ARE: 102, 103, 104, 105, 106, 107, 108, 109, 120 FREQUENCY OF UNIQUE DIGIT NUMBERS: 9 Example 2: INPUT: m = 2505 n = 2525 OUTPUT: THE UNIQUE DIGIT NUMBERS ARE: 2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2519 FREQUENCY OF UNIQU...

Generating Lucky Numbers Program in Java

Consider the sequence of the natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... Removing every second number produces: 1, 3, 5, 7, 9, ... Removing every third number produces: 1, 3, 7, 9, ... The process continues indefinitely by removing every 4th number, then 5th number and so on till after a fixed number of steps, certain natural numbers remain and these numbers are known as the lucky numbers. Write a program to generate and print the lucky numbers within the range of N natural numbers. import java.util.Scanner; public class Lucky{     public static void main(String args[]){         Scanner in = new Scanner(System.in);         System.out.print("N = ");         int n = Integer.parseInt(in.nextLine());         int arr[] = new int[n];         for(int i = 0; i < n; i++)             arr[i] = i + 1;          int del = 1; ...

Add Two Binary Numbers in Java

Write a Java program to input two binary numbers from the user, and find and display their sum. Following are the rules for adding binary digits: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 with carry 1 1 + 1 + 1 = 1 with carry 1 Example: INPUT: 1011 101 OUTPUT: 10000 import java.util.Scanner; class BinaryAddition{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.print("First binary number: ");         String b1 = in.nextLine();         System.out.print("Second binary number: ");         String b2 = in.nextLine();         while(b1.length() < b2.length())             b1 = "0" + b1;         while(b2.length() < b1.length())             b2 = "0" + b2;         String sum = "";         c...