Skip to main content

Posts

Showing posts with the label Java

Math Library All Programs Solved Class 9 Java

[All Math library Programs From APC Class 9] import java.util.Scanner; class Q1{     public static void main(String args[]){         Scanner sc=new Scanner(System.in);         System.out.println("Enter three numbers:");         int a = sc.nextInt();         int b = sc.nextInt();         int c = sc.nextInt();         int g = Math.max(a,Math.max(b,c)); //greatest         int s = Math.min(a,Math.min(b,c)); //smallest         System.out.println("The greatest is:"+g);         System.out.println("The smallest is:"+s);     } } import java.util.Scanner; class Q2{     public static void main(String args[]){         Scanner sc=new Scanner(System.in);         System.out.println("Enter the perpendicular:");         int p = sc.nextInt...

Propositional Logic Notes Class 11 ISC

The concept of proposition means any statement which gives result either true or false. p: "Today is cold day" so p is the propositional constant and the rest is the statement.  There are two types of proposition: 1) Simple: Example is: p: "Today is holiday" q: " Dad is at home" 2)Complex/Compound: When we are combining multiple propositional statements into a single statement using logical connectives that is known as compound proposition. p and q: " Today is holiday and Dad is at home" over here"and" is the logical connective. There a multiple logical connectives such as: 1)Conjunction (and)  . / ^ 2)Disjunction (or) +/v 3) Negation (not) ~  4) Implication(if ....then) -> 5) Equivalence/Biconditional (if and only if) <=> or <-> 1) Conjunction   ------------------------ p: "Today is holiday" q: " Dad is at home" p^q: "Today is holiday and Dad is at home" Truth Table p.        q.    ...

ISC 2025 Theory Question: Colsum check

Design a class Colsum to check if the sum of elements in each corresponding column of two matrices is equal or not. Assume that the two matrices have the same dimensions. Example: INPUT: 2 3 1 7 5 6 1 4 2 MATRIX A 7 4 2 1 3 1 2 5 6 MATRIX B OUTPUT: Sum of corresponding columns is equal. The details of the members of the class are given below: Class name: Colsum Data members/instance variables: mat[][]: to store the integer array elements m: to store the number of rows n: to store the number of columns Member functions/methods: Colsum(int mm, int nn): parameterized constructor to initialize the data members m = mm and n = nn void readArray(): to accept the elements into the array boolean check(Colsum A, Colsum B): to check if the sum of elements in each column of the objects A and B is equal and return true, otherwise return false void print(): to display the array elements Specify the class Colsum giving details of the constructor, void readArray(), boolean check(Colsum, Colsum), and v...

ISC 2025 Theory Question Pernicious number

A class Perni has been defined to accept a positive integer in binary number system from the user and display if it is a Pernicious number or not. A pernicious number is a binary number that has minimum of two digits and has prime number of 1s in it. Examples: 101 is a pernicious number as the number of 1s in 101 = 2 and 2 is prime number. 10110 is a pernicious number as the number of 1s in 10110 = 3 and 3 is prime number. 1111 is NOT a pernicious number as the number of 1s in 1111 = 4 and 4 is NOT a prime number. The details of the members of the class are given below: Class name: Perni Data members/instance variables: num: to store a binary number Methods/Member functions: Perni(): constructor to initialize the data member with 0 void accept(): to accept a binary number (containing 0s and 1s only) int countOne(int k): to count and return the number of 1s in ‘k’ using recursive technique void check(): to check whether the given number is a pernicious number by invoking the function co...

ISC Program: Highest and Lowest ASCII code in lowercase and uppercase characters

 Write a program in Java to enter the string. Count and display: The character with lowest ASCII code in lower case The character with highest ASCII code in lower case The character with lowest ASCII code in upper case The character with highest ASCII code in upper case Sample Output: The character with lowest ASCII code in lower case: a The character with highest ASCII code in lower case: y The character with lowest ASCII code in upper case: E The character with highest ASCII code in upper case: P Solution: import ISjava.util.Scanner; class lowhighascii {     public static void main(){         Scanner sc=new Scanner(System.in);         System.out.println("Enter a sentence:");         String s = sc.nextLine();         int p=0,q=999,r=0,t=999;         for(int i=0;i<s.length();i++)         {             char ch = s.charAt(i...

ISC Program: Write a program in Java to accept a string and display the new string after reversing the characters of each word.

Write a program in Java to accept a string and display the new string after reversing the characters of each word. Sample Input: Understanding Computer Science Sample output: gnidnatsrednU retupmoC ecneicS Solution: import java.util.Scanner; class reverseEachWord {     public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter a sentence:");         String s=sc.nextLine()+" ";         String w="";         String res=" ";         for(int i=0;i<s.length();i++)         {             char ch = s.charAt(i);             if(ch==' ')             {                 String m="";                 for(int j=w.length()-1;j...

Java Mathematical Library Notes

Mathematical Library ---------------------- The math library is present under the package java.lang. Not under the package java.math . 1) Math.sqrt() -> return type is double. It returns the square root of a number. (a) double x = Math.sqrt(4);  => 2.0 (b) double y = Math.sqrt(-4); => NaN (Not a number) (for any negative value the answer is always NaN) 2) Math.cbrt() -> return type is double. It returns the cube root of a number (a) double x = Math.cbrt(8); => 2.0 (b) double y = Math.cbrt(-125); => -5.0 3) Math.pow() -> return type is double  Syntax:  Math.pow(base,exponent) 5 to the power of 3 (here 5 is base and 3 is exponent) (a) double x = Math.pow(5,3); => 125.0 (b) double y = Math.pow(16,1/2); => Math.pow(16,0); => 1.0     here 1/2 is 0 (L<R,/,0 when both are integer) (c) double z = Math.pow(16,1.0/2); => Math.pow(16,0.5) => 4.0 (d) double a = Math.pow(-16,1.0/2); => NaN  (e) double b = Math.pow(64,1.0/3); =...

ISC Program: Predict day of the week from date

Algorithm : 1)Take the last two digits of the year. 2)Divide by 4, discarding any fraction. 3)Add the day of the month. 4)Add the month's key value: JFM AMJ JAS OND 144 025 036 146 5)Subtract 1 for January or February of a leap year. 6)For a Gregorian date, add 0 for 1900's, 6 for 2000's, 4 for 1700's, 2 for 1800's; for other years, add or subtract multiples of 400. 7)For a Julian date, add 1 for 1700's, and 1 for every additional century you go back. 8)Add the last two digits of the year. 9)Divide by 7 and take the remainder. Example : Let's take a date: 26/03/2027 Last two digit of the year = 27 Divide by 4 discard fraction = 27/4 = 6.75 = 6 Add day = 6 + 26 = 32 Month key = 4 + 32 = 36 Add year code = 36 + 6 = 42 Now add two digits of the first year = 42 + 27 = 69 Now get the remainder after dividing by 7 = 69%7=6 So 1 is Sunday so 6 is Friday So 27/03/2027 Program : import java.util.Scanner; public class daydate {     public static void main(String[] arg...

ISC Program : Position deletion in a sentence

  WAP to accept  a sentence which may be terminated by either , ; ? . or !(Any other character may be ignored). The words may be separated by more than one blank space and are in upper case. Perform the following tasks: (i) Accept the sentence and reduce all extra blank spaces between two words to a single blank space. (ii) Accept a word from the user which is a part of the sentence along with its position number and delete the word and display the distance. Example: Input: AS YOU SOW,SO SO YOU REAP. AS YOU SOW,SO SO YOU REAP Word To be deleted : SO Word position in the sentence: 4 Output: AS YOU SOW,SO YOU REAP import java.util.*; public class code {     public static void main( String [] args) {         Scanner sc= new Scanner(System.in);         System.out.println( "Enter a sentence:" );         String m = sc.nextLine();         char ch = m.charAt(m.length()- 1 );   ...

ISC 2021 Program: Fascinating Number

Write a Program in Java to input a number and check whether it is a Fascinating Number or not. Fascinating Numbers: Some numbers of 3 digits or more exhibit a very interesting property. The property is such that, when the number is multiplied by 2 and 3, and both these products are concatenated with the original number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes. Let's understand the concept of Fascinating Number through the following example: Consider the number 192 192 x 1 = 192 192 x 2 = 384 192 x 3 = 576 Concatenating the results: 192 384 576 It could be observed that '192384576' consists of all digits from 1 to 9 exactly once. Hence, it could be concluded that 192 is a Fascinating Number. Some examples of fascinating Numbers are: 192, 219, 273, 327, 1902, 1920, 2019 etc. /**  * suppose 192  * 192x1=192  * 192x2=384  * 192x3=576  * 192384576  * no single digit should repeat */ import java.util.Scanner; class fasc...

Money Object Passing Program in Java

 /**    Money is an unit that has 2 parts, Rupees and Paise, where 100 Paise=1 Rupee. Design a  class named Money whose details are as follows: Class Name : Money Data member: int rs, ps  : integer to store the value of Rupees and paise. Member methods: Money(…..)     : parameterized constructor to initialize member data void fnShow()  : to show the member data as Money [Rs 819.75] Money fnAdd(Money m1, Money m2) : Add m1 and m2. Store the result in corresponding member data and return it. Specify the class Money, giving the details of the above member data and methods.  Also write the main() to create objects and call the other methods accordingly to  enable the task of the adding 2 units on Money.    */ import java.util.Scanner; public class Money {     int rs,ps;     Money(int rs,int ps)     {         this.rs=rs;         this.ps=ps;     } ...

Object Passing Program in Java: Point Coordinate Program

A class defines the coordinates of a point in a plane. The details of the class are given below: class name: point Instance variables: int x,y --> define the x and y coordinate void input(): To accept the x and y coordinates void calculate(point p): To pass the object which depicts the 2nd coordinate. Then find the distance between the two coordinates. import java.util.Scanner; public class Point  {     int x,y;     void input(){         Scanner sc=new Scanner(System.in);         System.out.println("Enter x coordinate:");         x=sc.nextInt();         System.out.println("Enter y coordinate:");         y=sc.nextInt();         sc.close();     }     void calculate(Point p)     {         int x1 = this.x;         int y1 = this.y;         int x2 = ...

Implementation of Dequeue(Double ended queue) in Java

 Implementation of Dequeue(Double ended queue) in Java class dequeue { //double ended queue int DQ[],f=-1,r=-1,size; dequeue(int size) { this.size=size; DQ = new DQ[size]; } void addFront(int data) { if(f==-1 && r==-1) { f=0;r=0; } else if(f==0) { System.out.println("Queue overflow"); } else{ f=f-1; } DQ[f]=data; } void deleteFront() { if(f==-1 && r==-1) { System.out.println("Queue underflow"); } int v=DQ[f]; System.out.println("Removed:"+v); f=f+1; } void addRear(int data) { if(f==-1 && rear==-1) { f=0; r=0; } else if(rear==(size-1)) { System.out.println("Queue Overflow"); } else { r=r+1; } DQ[r]=data; } void removeRear() { if(f==-1 && r==-1) { System.out.println("Queue is underflow"); } if(f==r) { System.out.println("Removed element is:"+DQ[r]); f=-1; r=-1; } else { System.out.println("Removed element is:"+DQ[r]); r=r-1; } } void display() { if(f==-1 && r==-1) System.out.prin...

ShiftRows 2025 ISC Practical

  Write a 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 both M and N must be greater than 2 and less than 10. Allow the user to input integers into this matrix. Display appropriate error message for an invalid input. Perform the following tasks on the matrix: (a) Display the input matrix. (b) Shift each row one step upwards so the first row becomes the last row, 2 nd row will be the 1 st row and so on. (c) Display the rotated matrix along with the highest element and its location in the matrix. Test your program for the following data and some random data: Example 1 INPUT: M = 3 N = 4 Enter elements in the matrix: 100 90 87 76 200 500 167 998 77 567 89 254 OUTPUT: FORMED MATRIX AFTER ROTATING: 200 500 167 998 77 567 89 254 100 90 87 76 Highest element: 998 (Row: 0 and Column: 3) Example 2 INPUT: M = 4 N = 3 Enter elements in the matrix: 54 120 187 78 55 289 134 67 89 63 341 122 OUTPUT: FORMED MATRIX A...