Posts

Showing posts with the label isc computer science

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

Find the Longest and the Shortest Words in a Sentence in Java

Write a Java Program to input a sentence and find and display the longest and the shortest words from that sentence along with their lengths. import java.util.Scanner; class Find{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.print("Sentence: ");         String s = in.nextLine().trim().toUpperCase();         char last = s.charAt(s.length() - 1);         if(".!?".indexOf(last) == -1){             System.out.println("Invalid sentence!");             return;         }         String word = new String();         String longest = new String();         String shortest = new String(s);         for(int i = 0; i < s.length(); i++){           ...

Adders in Digital Logic

Image
Definition of Half Adder A half adder is a logic circuit that adds two bits. It generates two outputs: SUM and CARRY. The boolean equations for SUM and CARRY are: Equation SUM = A  ⊕ B = A'B + AB' CARRY = A . B Truth Table A B CARRY SUM 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 Following is the logic circuit diagram for half adder: Circuit Diagram Definition of Full Adder A full adder is a logic circuit that adds three bits. It generates two outputs: SUM and CARRY. Equation SUM = A  ⊕   B  ⊕ C = (A'B'C + A'BC' + AB'C' + ABC) CARRY = AB + BC + CA Truth Table A B C CARRY SUM 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 Circuit Diagram

Merge Sort Program in Java

The Merge Sort is a sorting algorithm which is based on the divide-and conquer approach. It works as follows: It divides a list into two halves. Sort the two halves recursively using merge sort. Merge the two sorted halves to form the final sorted list. Below is the Java program that implements merge sort on a list of integers stored in an array: import java.util.Scanner; class MergeSort{     int arr[];     int capacity;     public MergeSort(int size){         capacity = size;         arr = new int[capacity];     }     public void input(){         Scanner in = new Scanner(System.in);         System.out.println("Enter " + capacity + " elements:");         for(int i = 0; i < arr.length; i++)             arr[i] = Integer.parseInt(in.nextLine());     }     public void recur(int a[], int lo...

Binary Search Tree Program in Java

A binary tree  is a non-linear data structure. In a binary tree, each node can have a maximum of two children. A binary tree in which its information is sorted in inorder way is a binary search tree (BST), meaning, the value of each node is greater than or equal to every value in its left subtree, and is less than every value in its right subtree. The depth of a node is the number of edges in the path from the root to that node. The height of a node is the number of edges in the longest path from that node to a leaf node. The size of a tree is the count of the total number of nodes in it. A binary tree is of degree 2 because it can have a maximum of two children. A node with no successor is a leaf node. The internal nodes are the ones with at least one successive node. A line connecting a node to its successor is an edge . A sequence of continuous edges make a path . Two nodes with the same parent are siblings . A node with no parent is the root . Every node other than the ro...

Matrix Transpose ISC Computer Science 2009 Theory

A transpose of an array is obtained by interchanging the elements of the rows and columns. A class Transarray contains a two-dimensional integer array of order (m × n). The maximum value possible for both 'm' and 'n' is 20. Design a class Transarray to find the transpose of a given matrix. The details of the members of the class are given below: Class name : Transarray Data members/instance variables : arr[][]: stores the matrix elements m: integer to store the number of rows n: integer to store the number of columns Member functions : Transarray(): default constructor Transarray(int row, int col): to initialize the size of the matrix as m = row, n = col void fillArray(): to enter the elements of the matrix void transpose(Transarray a): to find the transpose of a given matrix void dispArray(): displays the array in a matrix form Specify the class Transarray giving details of the constructors, void fillArray(), void transpose(Transarray) and void dispArray(). You need ...

Remove Duplicate Elements from an Integer Array in Java

Write a program in Java to remove all the duplicate elements in a one-dimensional array. The details of the class, its variables and member functions are given below: Class name : Remove Data members/instance variables : a[]: integer array to store the elements n: to store the size of the array Methods : Remove(int m): parameterized constructor to store n = m void input(): to enter the elements in the array void duplicate(): to remove all the duplicate elements from the array void display(): to display the final array Also write the main() method to create an object of the class and call the methods accordingly to enable the task. import java.util.Scanner; class Remove{     int a[];     int n;     public Remove(int m){         n = m;         a = new int[n];     }     public void input(){         Scanner in = new Scanner(System.in);         System.out.println...

Date Validity Program ISC Computer Science 2011 Practical

Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not. If it is valid, display "VALID DATE" and also compute and display the day number of the year for the date of birth. If it is invalid, display "INVALID DATE" and then terminate the program. Test your program for the given sample data and some random data. Example 1 : INPUT: Enter your date of birth in dd mm yyyy format: 05 01 2010 OUTPUT: VALID DATE DAY NUMBER: 5 Example 2 : INPUT: Enter your date of birth in dd mm yyyy format: 03 04 2010 OUTPUT: VALID DATE DAY NUMBER: 93 Example 3 : INPUT: Enter your date of birth in dd mm yyyy format: 34 06 2010 OUTPUT: INVALID DATE import java.util.Scanner; class MyDate{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.println("Enter your date of birth in dd mm yyyy format: ");         int dt = Integer.pars...

Encryption Program ISC Computer Science 2011 Practical

Encryption is a technique of coding messages to maintain their secrecy. A string array of size 'n' where 'n' is greater than 1 and less than 10, stores single sentences (each sentence ends with a full stop) in each row of the array. Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of the odd rows with an encryption of two characters ahead of the original character. Also change the sentence of the even rows by storing the sentence in reverse order. Display the encrypted sentences as per the sample data given below: Test your program on the sample data and some random data. Example 1 : INPUT: n = 4 IT IS CLOUDY. IT MAY RAIN. THE WEATHER IS FINE. IT IS COOL. OUTPUT: KV KU ENQWFA. RAIN MAY IT. VJG TGCVJGT KU HKPG. COOL IS IT. Example 2 : INPUT: n = 13 OUTPUT: INVALID ENTRY import java.util.Scan...

Display Number in Words ISC Computer Science 2011 Practical

Write a program to input a natural number less than 1000 and display it in words. Test your program for the given sample data and some random data. INPUT: 29 OUTPUT: TWENTY NINE INPUT: 17001 OUTPUT: OUT OF RANGE INPUT: 119 OUTPUT: ONE HUNDRED AND NINETEEN INPUT: 500 OUTPUT: FIVE HUNDRED import java.util.Scanner; class Words{     public static void main(String[] args){         Scanner in = new Scanner(System.in);         System.out.println("Enter natural number < 1000");         int num = Integer.parseInt(in.nextLine());         if(num >= 1000){             System.out.println("OUT OF RANGE");             return;         }         int hundreds = num / 100;         int tens = (num % 100);         int ones = (num % 100) % 10;         Strin...

Bank Inheritance Program ISC Specimen 2023 Theory

A super class Bank has been defined to store the details of the customer in a bank. Define a subclass Interest to calculate the compound interest. The details of the members of both the classes are given below: Class name : Bank Data members/instance variables : name: to store the name of the customer accNo: integer to store the account number principal: to store the principal amount in decimals Methods/member functions : Bank(...): parameterized constructor to assign values to the data members void display(): to display the customer details Class name : Interest Data members/instance variables : rate: to store the interest rate in decimals time: to store the time period in decimals Methods/member functions : Interest(...): parameterized constructor to assign values to the data members of both the classes double calculate(): to calculate and return the compound interest using the formula: CI = P(1 + R / 100) N - P, where P is the principal, R is the rate and N is the time void displ...

Holder Queue ISC Specimen 2023 Theory

Holder is a kind of data structure which can store elements with the restriction that an element can be added from the rear end and removed from the front end only. Class name : Holder Data members/instance variables : q[]: array to hold integers cap: maximum capacity of the holder front: to point the index of the front end rear: to point the index of the rear end Methods/Member functions : Holder(int n): constructor to initialize cap = n, front = 0 and rear = 0 void addInt(int v): to add integers in the holder at the rear end if possible, otherwise display the message "HOLDER IS FULL" int removeInt(): removes and returns the integers from the front end of the holder if any, else returns -999 void show(): displays the elements of the holder (i) Specify the class Holder giving details of the function void addInt(int) and int removeInt(). Assume that the other functions have been defined. import java.util.Scanner; class Holder{     int q[];     int cap;     ...

Encrypt Program ISC Specimen 2023 Theory

A class Encrypt has been defined to replace only the vowels in a word by the next corresponding vowel and forms a new word, i.e. A → E, E  → I, I  → O, O  → U and U  → A. Example : Input: COMPUTER Output: CUMPATIR Some of the members of the class are given below: Class name : Encrypt Data members/instance variables : wrd: to store a word len: integer to store the length of the word newWrd: to store the encrypted word Methods/Member functions : Encrypt(): default constructor to initialize data members with legal initial values void acceptWord(): to accept a word in uppercase void freqVowCon(): finds the frequency of the vowels void nextVowel(): replaces only the vowels from the word stored in 'wrd' by the next corresponding vowel and assigns it to 'newWrd', with the remaining alphabets unchanged void disp(): displays the original word along with the encrypted word Specify the class Encrypt giving details of the constructor, void acceptWord(), void freqVowCon(), void ...

Odd Even ISC Specimen 2023 Theory

Design a class OddEven to arrange two single dimensional arrays into one single dimensional array, such that the odd numbers from both the arrays are at the beginning followed by the even numbers. Example : Array 1: {2, 13, 6, 19, 26, 11, 4} Array 2: {7, 22, 4, 17, 12, 45} Arranged Array = {13, 19, 11, 7, 17, 45, 2, 6, 26, 4, 22, 4, 12} Some of the members of the class are given below: Class name : OddEven Data members/instance variables : a[]: to store integers in the array m: integer to store the size of the array Methods/Member functions : OddEven(int num): parameterized constructor to initialize the data member m = num void fillArray(): to enter integer elements in the array OddEven arrange(OddEven p, OddEven q): stores the odd numbers from both the parameterized object arrays followed by the even numbers from both the arrays and returns the object with the arranged array void display(): displays the elements of the arranged array Specify the class OddEven giving details of the co...