Skip to main content

Posts

Showing posts with the label ICSE

A departmental shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task. Hint: Number of stores as rows and Number of departments as columns.

 A departmental shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task. Hint: Number of stores as rows and Number of departments as columns. import java.util.Scanner; class Department{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int deptshop[][] = new int[5][6]; //5 stores(rows) 6 deparments(columns) int sales[] = new int[5]; //total sales data for 5 stores for(int i=0;i<5;i++){ //row System.out.println("Enter data for store:"+(i+1)); int sum=0; for(int j=0;j<6;j++){ //column System.out.println("Enter sales amount into department "+(j+1)); deptshop[i][j]=sc.nextInt(); sum=sum+deptshop[i][j]; } sales[i]=sum; //store the total sales amount for each store } ...

Write a program to accept the starting and ending range. Display the sum of even and odd numbers .

Write a program to accept the starting and ending range. Display the sum of even and odd numbers . import java.util.Scanner; public class Range {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);                                   System.out.println("Enter the starting and ending range:");         int m = sc.nextInt();         int n = sc.nextInt();         if(m<n){             int so=0,se=0;             for(int i=m;i<=n;i++)             {                 if(i%2==0)                 {                     se=se+i;        ...

Write a program to accept 50 numbers. Count and display the numbers which are positive and negative.

Write a program to accept 50 numbers. Count and display the numbers which are positive and negative. import java.util.Scanner; class posneg {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter 50 numbers:");         int nc=0,pc=0;         for(int i=1;i<=50;i++)         {             System.out.println("Enter number:");             int n=sc.nextInt();             if(n>=0)             {                 pc=pc+1;                 System.out.println(n+" is positive number");             }             else{          ...

Write a program to accept a word. Check if the word is a happy word or not.

/** Suppose : VAT ASCII code of V : 86 -64 => 22 ASCII code of A : 65 - 64 => 1 ASCII code of T : 84 - 64 => 20 Position of V: 22 Position of A: 1 Position of T: 20 Subtract the ascii value with 64,so we get the position values To join the position values together, VAT => 22120 We need to perform this calculate 2*2+2*2+1*1+2*2+0*0 => 13 1*1+3*3 => 10 1*1+0*0 => 1 If we get 1 at the very end, then this is Happy Word */ import java.util.Scanner; class HappyWord {  public static void main(String args[])  {   Scanner sc = new Scanner(System.in);   System.out.println("Enter a word: ");   String str = sc.next().toUpperCase();   String num="";   for(int i=0;i<str.length();i++)   {    char ch = str.charAt(i); //we get each every character    int ascii = (int)ch;    int pos=ascii-64;    num=num+Integer.toString(pos);   }   System.out.println("The combined position is "+num);   i...

Write a program to accept a sentence. Display the word with maximum number of vowel.

Write a program to accept a sentence. Display the word with maximum number of vowel. import java.util.Scanner; class maxvowel {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter a sentence:");         String str=sc.nextLine()+" ";         String w="",mvw=""; //w word and mvw maximum vowel word          int mv=0; //maximum vowels         for(int i=0;i<str.length();i++)         {             char ch=str.charAt(i);             if(ch==' ')             {                 int nv=0; //number of vowels                  for(int j=0;j<w.length();j++)         ...

Write a program to accept a sentence. Find the shortest word present in the sentence.

Write a program to accept a sentence. Find the shortest word present in the sentence. import java.util.Scanner; class shortestWord {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Enter a sentence:");         String str=sc.nextLine()+" ";         int min=99999;         String w="",sw=""; //w for word          for(int i=0;i<str.length();i++)         {             char ch=str.charAt(i);             if(ch==' ')             {                 if(w.length()<min)                 {                     min=w.length();       ...

Write a program to accept 5 student names and their marks. Display the names in the descending order of the marks using bubble sort algorithm.

Write a program to accept 5 student names and their marks. Display the names in the descending order of the marks using bubble sort algorithm. Input: Ravi 25 Sheetal 30 Rajeev 27 Karan 28 Utsav 24 Output: Sheetal 30 Karan 28 Rajeev 27 Ravi 25 Utsav 24 import java.util.Scanner; class meritlist { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String names[] = new String[5]; int marks[] = new int[5]; System.out.println("Enter 5 names and their marks:"); for(int i=0;i<5;i++) { System.out.println("Enter name:"); names[i]=sc.next(); System.out.println("Enter marks:"); marks[i]=sc.nextInt(); } for(int i=0;i<5-1;i++) { for(int j=0;j<5-i-1;j++) { if(marks[j]<marks[j+1]) //for ascending order marks[j]>marks[j+1] { //marks sorting descending order  int t = marks[j]; marks[j=marks[j+1]; marks[j+1]=t; //name sortin...

Write a program to accept 5 names and their age. Arrange the names in ascending order along with their age.

Write a program to accept 5 names and their age. Arrange the names in ascending order along with their age. Input: Sheetal 25 Ishita 24 Punam 28 Avishek 20 Raima   22 Output: Avishek 20 Ishita  24 Punam 28 Raima 22 Sheetal 25 import java.util.Scanner; class sortnames { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter 5 names and their age:"); String names[] = new String[5]; int age[] = new int[5]; for(int i=0;i<5;i++) { System.out.println("Enter names:"); names[i]=sc.next(); System.out.println("Enter age:"); age[i]=sc.nextInt(); } for(int i=0;i<5-1;i++) { for(int j=0;j<5-i-1;j++) { if(names[j].compareTo(names[j+1])>0) //>0 means ascending and <0 means descending { //name sort  String t=names[j]; names[j]=names[j+1]; names[j+1]=t; //age sort int temp = age[j]; age[j]=age...

Write a program to accept a 3x3 matrix. Display the square of the product of the left and right diagonal sum of the matrix.

Write a program to accept a 3x3 matrix. Display the square of the product of the left and right diagonal sum of the matrix. Input Matrix: 1   2    3 4   5    6 7   8    9 Output :   Product of the left diagonal = 1*5*9=45 Product of the right diagoal = 3*5*7 = 105 Sum of the products 45+105 = 150 Square of the sum = 12.2 import java.util.Scanner; class matrixsquare { public static void main(String args[]) { int A[][] = new int[3][3]; // 3 rows and 3 columns Scanner sc=new Scanner(System.in); System.out.println("Enter numbers into the matrix:"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { A[i][j]=sc.nextInt(); } } int ld=1,rd=1; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { ld=ld*A[i][i]; //left diagonal product rd=rd*A[i][3-i-1]; //right diagoal product  } } int sp = ld+rd; //sum of the product  double sq = Math.sq...

ICSE Class 9 Up to Conditional Statements 100 MCQs with answers

**Theory-Based Questions (1-50)** **1. Which of the following is a low-level language?**   A) Java   B) Python   C) Assembly Language   D) C++   **Answer: C** **2. What is the function of an assembler?**   A) Converts high-level code to machine code   B) Converts assembly code to machine code   C) Converts bytecode to machine code   D) Converts source code to object code   **Answer: B** **3. Which principle of OOP allows a function to be used for multiple purposes?**   A) Encapsulation   B) Inheritance   C) Polymorphism   D) Data Abstraction   **Answer: C** **4. Which Java package is imported by default?**   A) java.util   B) java.io   C) java.lang   D) java.awt   **Answer: C** **5. What is the extension of a Java source code file?**   A) .class   B) .java   C)...

ICSE Class 9 Loop based Multiple Choice Questions With Explanation

92 MCQ Set Of Questions **1. What is the output of the following code?** ```java int a = 5, b = 2; int result = a++ * --b; System.out.println(result + " " + a + " " + b); ``` a) 10 6 1 b) 5 6 1 c) **5 6 1** d) 10 5 1 **2. What will be the value of `sum` after execution?** ```java int sum = 0; for(int i = 1; i <= 5; i+=2) {     sum += i; } ``` a) 6 b) 9 c) **15** d) 10 **3. Predict the output:** ```java int x = 10; if(x++ > 10 && ++x < 12) {     System.out.println(x); } else {     System.out.println(x+1); } ``` a) 10 b) 11 c) **12** d) 13 **4. What does this code print?** ```java System.out.println(13 / 5 + " " + 13 % 5); ``` a) 2.6 3 b) 2 3 c) **2 3** d) 3 2 **5. What is the output?** ```java int a = 1; int b = a++ + ++a * a++; System.out.println(b); ``` a) 10 b) **11** c) 12 d) 13 *Explanation: The expression is evaluated as 1 + (3 * 3). a++ is 1 (then a=2), ++a makes a=3, the third a++ is 3 (then a=4). So 1 + 9 = 10.* **6. Predict the ou...

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