ICSE 2022 SEM-2 QUESTION 7 SOLVED

 /* Define a class to accept two strings of same length and form a new word in such a way that, the first character of the 

 * first word is followed by the first character of the second word and so on.

 * Example - Input: String 1 : BALL

 * String 2 : WORD

 * Output : BWAOLRLD

 */

import java.util.*;

class QUESTION_7

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter the first string:");

        String st=sc.nextLine();

        System.out.println("Enter the second string:");

        String str=sc.nextLine();

        String wrd="";

        if(st.length()==str.length())

        {

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

            {

                wrd=wrd+st.charAt(i)+str.charAt(i);

            }

            System.out.println("Output: "+wrd);

        }

        else

        System.out.println("Both the word should be of same length");

    }

}

ICSE 2022 SEM-2 QUESTION 6 SOLVED

 /* Define a class to declare an array to accept and store ten words. Display only those words which letter begin with the letter

 * 'A' or 'a' and also end with the letter 'A' or 'a'.

 * Example - Input: Hari, Anita, Akash, Amrita, Alina, Devi, Rishab, John, Farha, AMITHA

 * Output: Anita

 * Amrita

 * Alina

 * AMITHA

 */

import java.util.*;

class QUESTION_6

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        String st[]=new String[10];

        System.out.println("Enter 10 words:");

        for(int i=0;i<10;i++)

        {

            st[i]=sc.next();

        }

        System.out.println("Words starting and ending with letter 'a'||'A' are :");

        for(int i=0;i<10;i++)

        {

            char ch=st[i].charAt(0);

            char ch1=st[i].charAt(st[i].length()-1);

            if((ch=='a' || ch=='A') && (ch1=='a' || ch1=='A'))

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

        }

    }

}

ICSE 2022 SEM-2 QUESTION 5 SOLVED

 /* Define a class to accept a string, and print the characters with the uppercase and lowercase reversed, but all the other

 * characters should remain the same as before.

 * Example: Input : WelCoMe_2022

 * Output : wELcOmE_2022

 */

import java.util.*;

class QUESTION_5

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        String str;

        System.out.println("Enter a String :");

        str=sc.nextLine();

        int l=str.length();

        for(int i=0;i<l;i++)

        {

            char ch=str.charAt(i);

            if(Character.isLowerCase(ch))

            System.out.print(Character.toUpperCase(ch));

            else if(Character.isUpperCase(ch))

            System.out.print(Character.toLowerCase(ch));

            else

            System.out.print(ch);

        }

    }

}

ICSE 2022 SEM-2 QUESTION 4 SOLVED

 /* Define a class to declare an array of size twenty of double datatype, accept the elements into the array and perform the 

 * following: 1. Calculate and print the product of all the elements

 * 2. Print the square of each element of the array

 */

import java.util.*;

class QUESTION_4

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        double n[]=new double[20];

        double p=1;

        System.out.println("Enter 20 elements :");

        for(int i=0;i<5;i++)

        {

            n[i]=sc.nextDouble();

            p=p*n[i];

        }

        System.out.println("Square of all the elements:");

        System.out.println("Element\t\tSquare");

        System.out.println("-------\t\t------");

        for(int i=0;i<5;i++)

        {

            System.out.println("  "+n[i]+"\t\t\t"+n[i]*n[i]);

        }

        System.out.println("Product of all the elements: "+p);

    }

}

ICSE 2022 SEM-2 QUESTION 3 SOLVED

 /* Define a class to declare a character array of size ten, accept the characters into the array and display the characters with

 * highest and lowest ASCII value.

 * Example: Input:

 * 'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F'

 * Output:

 * Character with highest ASCII value = z

 * Character with lowest ASCII value = A

 */

import java.util.*;

class QUESTION_3

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        char ch[]=new char[10];

        int max=0,min=0;

        System.out.println("Enter ten characters:");

        for(int i=0;i<10;i++)

        {

            ch[i]=sc.next().charAt(0);

        }

        min=ch[0];

        for(int i=0;i<10;i++)

        {

            if(ch[i]<min)

            min=ch[i];

            if(ch[i]>max)

            max=ch[i];

        }

        System.out.println("Character with highest ASCII value = "+(char)max);

        System.out.println("Character with lowest ASCII value = "+(char)min);

    }

}

ICSE 2022 SEM-2 QUESTION 2 SOLVED

 /* Define a class to perform binary search on a list of integers given below, to search for an element to input by the user,

if it is found display the element along with is position, otherwise display the message "Search element not found"

2, 5, 7, 10, 15, 20, 29, 30, 46, 50 */

import java.util.*;

class QUESTION_2

{

    public static void main(String[]args)

    {

        Scanner sc=new Scanner(System.in);

        int ar[]={2, 5, 7, 10, 15, 20, 29, 30, 46, 50};

        int lc=0,uc=ar.length,mid=0,p=0,k=0;

        System.out.println("Enter a number to be search:");

        int n=sc.nextInt();

        while(uc>lc)

        {

            mid=(lc+uc)/2;

            if(ar[mid]>n)

            uc=mid-1;

            if(ar[mid]<n)

            lc=mid+1;

            if(ar[mid]==n)

            {

                p=mid;

                k=1;

                break;

            }

        }

        if(k==1)

        {

            System.out.println(n+" is presnt in "+(p+1)+" position");

        }

        else

        {

            System.out.println("Search element not found");

        }

    }

}

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...