0% found this document useful (0 votes)
16 views6 pages

RevisionTerm1 QP

The document contains a series of programming questions and tasks related to Java, focusing on string manipulation, loops, conditional statements, and class design. It includes specific coding challenges such as checking for lowercase characters, calculating factorials, and determining if numbers are Armstrong or perfect. Additionally, it requires the implementation of classes to perform various operations on numbers and strings.

Uploaded by

shahprithvi01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

RevisionTerm1 QP

The document contains a series of programming questions and tasks related to Java, focusing on string manipulation, loops, conditional statements, and class design. It includes specific coding challenges such as checking for lowercase characters, calculating factorials, and determining if numbers are Armstrong or perfect. Additionally, it requires the implementation of classes to perform various operations on numbers and strings.

Uploaded by

shahprithvi01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Shri Vile Parle Kelavani Mandal’s

C.N.M.School & N.D.Parekh Pre-Primary School


Academic Year (2023-24)
Computer Science - Revision - XI
Q1. Write a statement each to perform the following task on a string:
i) Check if the third character of a string str is in lowercase.
ii) Extract the last character of a word stored in the variable wd.
iii) Check if the String str ends with character ‘p’.
iv) Find and display the position of the last space in a string s.
Q2. What will be the output of following segment?
i) double res= Math.pow(“345”.indexOf(“5”),3);
System.out.println(res);
ii) String sub= “Computer Application”;
char c1=Character.toUpperCase(sub.charAt(0));
char c2=Character.toUpperCase(sub.charAt(sub.lastIndexOf(” “)+1));
System.out.println(c1 +” “+ c2);
iii) double m=-3.8, n=1.5;
System.out.println(Math.min(Math.floor(m),n));
System.out.println(Math.max(Math.ceil(n),m));
iv) If String k = “Malayalam”;
a) k.lastIndexOf(‘a’);
b) for(int k =str.length()-1 ; k<=0 ; k--)
System.out.print(str.charAt(k));
v) System.out.println(Math.abs(Math.ceil(-4.3)));
vi) System.out.println(Math.pow(Math.sqrt(25),3));
vii) System.out.println(“Hello World”.lastIndexOf(“Hello”.charAt(2)));
viii) System.out.println(“Wrestling World”. substring(8));
ix) System.out.println((“Application”.lastIndexOf(“A”)));
x) String a= “Laptop”, b= “Roof top”;
String h=a.substring(3,6);
String k=b.substring(5).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
xi) String str= “APPLICATION”;
System.out.println(str.indexOf(str.charAt(8)));
xii) System.out.println( (“DEVOTE”.compareTo(“DEDICATE”)));
xiii) System.out.println( “CABLE”.compareTo(“CADET”));
xiv) int i = 0;
while (i<=1)
{
i++;
System.out.println(i);
}
System.out.println(i);
xv) int x=4,y=4;
x+= ++x + ++x;
y*= ++y + ++y;
System.out.println(x + “ ” + y);
xvi) String s= “Examination”;
int n=s.length();
System.out.println(s.startsWith(s.substring(5,n)));
System.out.println(s.charAt(2) == s.charAt(6));
Q3. State the output of the following program segment.
int sum=0;
for(int n=5;n<=1;n--)
{
sum+=n;
sum++;
}
System.out.println(sum);

Q4. What is the final value of ctr after the iteration process given below, executes?
int ctr=0;
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j+=2)
++ctr;
Q5. How many times will the following loop execute? What value will be returned?
int x = 2, y = 50;
do {
++x;
y-=x++;
}while(x<=10);
return y;
Q6. Analyse the given program segment and answer the following questions:
(i) Write the output of the program segment
(ii) How many times does the body of the loop gets executed?
for(int m=5; m<=20; m+=5)
{
if(m%3 == 0)
break;
else
if(m%5 == 0)
System.out.println(m);
continue;
}
Q7. Rewrite the following segment in ternary operator.

1) if(marks>40&&marks<=100)
Grage= ‘A’;
else
Garde=’F’;

2) if (bill<10000 )
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;

Q8. Use switch case statement for the given program snippet:
if(x = = 10)
a=r*2;
if(x = = 20)
a=r*4;
if(x = = 30)
a=r*6;
if(x = = 40)
a=r*8;
Q9. Convert following do-while loop into for loop.
int i=1; int d=5;
do{
System.out.println(i);
i++;
}while(i<=5);

Q10. The following function is a part of some class. It returns the value 1 when the number is an
Armstrong number, otherwise it returns 0. /* An Armstrong number is a number which is equal to
the sum of the cube of its individual digits*/
class Armstrong
{
int arms(int n)
{
int digit=0, sum=0;
int rem=n;
while(?1?)
{
digit=?2?;
sum=sum+?3?;
rem=?4?;
}
if(?5?)
return 1;
else
return 0;
}
}
i) What is the expression / value at ?1?
ii) What is the expression / value at ?2?
iii) What is the expression / value at ?3?
iv) What is the expression / value at ?4?
v) What is the expression / value at ?5?
Q11. Write a Java program to input a sentence from the user in lowercase and removes the first and
the last characters of every word in it.
Sample Input : i love java for school.
Sample Ouptut : ov av o choo
Some of the data members and member functions are given below:
Class name : Remove
Data members/instance variables:
sent : stores the sentence
rem : to store the new sentence
size : stores the length of the sentence
Member functions:
Remove() : default constructor
void readsentence() : to accept the sentence
void remfirstlast() : extract each word and remove the first and the last alphabet of the word
and form a new sentence using the changed words
void display() : display the original sentence along with the new changed sentence.
Specify the class Remove giving details of the constructor Remove (), void readsentence(), void
remfirstlast() and void display() . Define the main() function to create an object and call the function
accordingly to enable the task.

Q12. Design a class Perfect to check if a given number is a perfect number or not. [ A number is said
to be perfect if sum of the factors of the number excluding itself is equal to the original number]

Example : 6 = 1 + 2 + 3 (where 1, 2 and 3 are factors of 6, excluding itself) Some of the members of
the class are given below:

Class name : Perfect


Data members/instance variables:
num : to store the number
Methods/Member functions:

Perfect () : constructor to initialize the data member num


void accept() : accept the number using scanner class.
void check() : checks whether the given number is perfect or not and displays the result with
an appropriate message
Specify the class Perfect giving details of the constructor ( ), void accept( ) and void check ( ).
Define a main ( ) function to create an object and call the functions accordingly to enable the task.
Q13. A Special number is a number in which the sum of the factorial of its digits is equal to the
number. Example: 145 ( 1! + 4! + 5! = 145 ). Thus, 145 is a special number.

Design a class Special to check if the given number is a Special number or not. Some of the members
of the class are given below:

Class name : Special

Data members /instance variables :

n : integer to store the number

Member functions :

Special( ) : default constructor

void read( ) : to accept the number

int factorial(int x) : return the factorial of a number.

boolean isSpecial( ) : checks for the special number by invoking the function factorial(
) and returns true if Special, otherwise returns false

void display( ) : to show the result with an appropriate message.

Specify the class Special, giving details of the Constructor, void read( ), int factorial(int), boolean
isSpecial( ) and void display( ). Define the main() function to create an object and call the member
function according to enable the task.

***************************

You might also like