SOLVE COMPUTER APPLICATION SET-3 2022

Time allowed: One and a half hours

Answers to this Paper must be written on the paper provided separately.

You will not be allowed to write during the first 10 minutes.

This time is to be spent reading the question paper.

The time given at the head of this Paper is the time allowed for writing the answers.

Attempt all questions from Section A and any four questions from Section B.

SECTION A

(Attempt all questions.)

It appears that this quiz is not set up correctly

2. Define a class to accept a sentence and display those words that begin with a vowel.
Sample Input: A quick brown fox jumps over a lazy dog.
Sample Output: A over a

import java.util.*;   
public class Vowelwords  
{   
public static void main(String[] args)   
{
String st,st1;
st="";
st1=""; 
int i,l;    
char ch;    
Scanner in=new Scanner(System.in); 
st=in.nextLine();
l=st.length();
for(i=0;i< l;i++)    
{ 
    ch=st.charAt(i);
if (ch!=' ')     
{      
st1=st1+ch;     
}     
else     
{      
ch=st1.charAt(0);      
if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'||ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')       
System.out.print(st1 +" ");      
st1="";     
}    
}   
}  
}

Output:

A quick brown fox jumps over a lazy dog
A over a 

3. Write a program that reads a long number, counts, and displays the occurrences of each digit in it.

import java.util.*;   
public class Main   
{    
public static void main(String args[])    
{     
Scanner in = new Scanner(System.in);
long num,n,i,c,d,f;
System.out.print("Enter a number: ");     
num = in.nextLong();
for(i=0;i<=9;i++)
{
n=num;
c=0;
f=0;
while(n!=0)
{
    d=n%10;
    if(d==i)
    {
        c++;
        f=1;
    }
    n=n/10;
}
if(f>0)
System.out.println(i + "\t" + c);
}
}      
}

Output:

Enter a number: 452375
2	1
3	1
4	1
5	2
7	1

4. Write a program in Java to accept a word/a String and display the new string after removing all the vowels present in it.
Sample Input: COMPUTER APPLICATIONS
Sample Output: CMPTR PPLCTNS

import java.util.*;  
public class Main  
{   
public static void main(String args[])    
{    
Scanner in = new Scanner(System.in);
String st,st1;
char ch;
int i,l;
System.out.println("Enter a word or sentence:"); 
st = in.nextLine();
st=st.toUpperCase();
l = st.length(); 
st1 = "";     
for (i = 0; i < l; i++)    
{ 
ch=st.charAt(i);
if (ch == 'A'||ch == 'E'||ch == 'I'||ch == 'O'||ch == 'U')     
{      
continue;     
}     
st1 = st1 + ch;    
}    
System.out.println("String with vowels removed"); 
System.out.println(st1);   
}  
} 

Output:

Enter a word or sentence:
COMPUTER APPLICATIONS
String with vowels removed
CMPTR PPLCTNS

5. Define a class in Java to enter a String/Sentence and display the longest word and the length of the longest word present in the String.

Sample Input: “Sir Garry Sobers is one of the legends in InternationalCricket”

Sample Output :

The longest word: InternationalCricket: The length of the word: 20

Define a class in Java to enter a String/Sentence and display the longest word and the length of the longest word present in the String.

Sample Input: 
“Sir Garry Sobers is one of the legends in InternationalCricket”

Sample Output : 
The longest word: InternationalCricket: The length of the word: 20

import java.util.*;  
public class LongestWord  
{       
public static void main(String args[])   
{           
Scanner in = new Scanner(System.in);
int h,i,l,l1;
String st,st1,st2;
char ch;
System.out.println(“Enter a word or sentence:”);           
st = in.nextLine();                  
st = st+' '; //Add space at end of string           
st1= " ";
st2 =" ";
h=0;
l = st.length();                  
for (i = 0; i < l; i++)     
{               
ch = st.charAt(i);               
if (ch != ' ')     
{                                   
st1=st1+ch;
}               
else      
{                   
l1=st1.length();
if(l1>h)
{
    h=l1;
    st2=st1;
}
st1=" ";
}           
}           
System.out.println("The longest word: " + st2);
System.out.println("The length of the word: " +(h-1));       
}  
} 

Output:

Enter a word or sentence:
Sir Garry Sobers is one of the legends in InternationalCricket
The longest word:  InternationalCricket
The length of the word: 20

6. Define a class in Java to store 20 numbers in a Single Dimensional Array. Display the numbers which are composite.
Sample Input:

n[0]n[1]n[2]n[3]n[4]n[5]….n[16]n[17]n[18]n[19]
456577719067….82193152


Sample Output: 45,65,77,90,82,52

import java.util.Scanner;  
public class Main  
{   
public static void main(String args[])    
{    
Scanner in = new     Scanner(System.in);    
int arr[] = new int[20];
int i,c,n,j;
System.out.println("Enter 20  numbers"); 
for (i = 0; i < 20; i++)     
{     
arr[i] = in.nextInt();    
}    
System.out.println("Composite  Numbers:"); 
for (i = 0; i < 20; i++)    
{
n=arr[i];
c = 0;      
for (j = 1; j <= n; j++)     
{       
    if (n % j == 0)      
{        
    c++;       
}      
}      
if (c != 2)       
System.out.println(n + " ,");     
}     
}     
}

Output:

Enter 20  numbers
25
91
73
65
63
67
81
47
97
93
68
25
45
61
67
87
83
53
27
91
Composite  Numbers:
25 ,
91 ,
65 ,
63 ,
81 ,
93 ,
68 ,
25 ,
45 ,
87 ,
27 ,
91 ,

7. Define a class in Java to accept a word and display the ASCII code of each character of the word.
Sample Input: BLUEJ
Sample Output: ASCII of B = 66 ASCII of L = 76 ASCII of U = 85 ASCII of E = 69 ASCII of J = 74

import java.util.*;   
public class Main   
{    
public static void main(String args[])   
{     
Scanner in = new Scanner(System.in);
String word;
char ch;
int i,l,n;
System.out.println("Enter a word:");     
word = in.nextLine();     
l = word.length();     
for (i = 0; i < l; i++)    
{      
ch = word.charAt(i);
n=(int)ch;
System.out.println("ASCII of " + ch      + " = " + n);     
}    
}   
} 

Output:

Enter a word:
BLUEJ
ASCII of B = 66
ASCII of L = 76
ASCII of U = 85
ASCII of E = 69
ASCII of J = 74
Share your love