0% found this document useful (0 votes)
14 views2 pages

Class 10 Short Questions 2nd

The document contains a series of programming questions and tasks related to Java, including function prototypes, code outputs, error identification, and loop executions. It covers various topics such as string manipulation, arithmetic operations, array handling, and control structures. The questions require understanding of Java syntax and logic to derive outputs and correct errors.

Uploaded by

ayanacharya2009
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)
14 views2 pages

Class 10 Short Questions 2nd

The document contains a series of programming questions and tasks related to Java, including function prototypes, code outputs, error identification, and loop executions. It covers various topics such as string manipulation, arithmetic operations, array handling, and control structures. The questions require understanding of Java syntax and logic to derive outputs and correct errors.

Uploaded by

ayanacharya2009
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/ 2

1 Give the Prototype of the function to receive a character value and an integer value and which returns true

rue if the ASCII code of the character


value is equal to the integer value and false otherwise.
2 Give a statement of the following :
a) To replace the character H with the character T in the string str.
b) To check whether the character ch is a capital letter or not.
3 What will be the output of the following code:
String a=”Board Examination”;
System.out.println(a.substring(11).cjharAt(4));
System.out.println(a.lastIndexOf(‘a’));
4 What will be the output of the following:
int a=10, b=3;
a+=++a + b++ + --b;
b=(b++) +(--a) – (a--);
System.out.println(a+” “+b);
5 What will be the output of the following and how many times the loop is going to run? (Show the dry run )
int ctr=0;
do
{
System.out.println(ctr);
}while(ctr++<5);
6 How many comparisons will it take to find a number in the array using binary search given the array and the number as under.
Array 5 18 38 56 60 65 67 80 85 90
Number to be found (n=18)
7 What will be the output of the following code:
Double a=2.0, b=6.5; System.out.println(Math.pow(a,Math.rint(b)));
8
Write the java expression for the following
9 What is the error in the following code and why? 10 Rewrite the following using ternary operator.
class ABC String s;
{ if(a<=40)
Public void main(int a, int b) {
{ if(b<=60)
int(a>b) S=”Good”;
{ else
int d=a-b; S=”Bad”;
} }
System.out.println(“The result is”+d); else
} {
} S=”Fair”;
}
11 What will be the result of the following:
“RESULT”.compartTo(“RESTART”)+”RAILWAYMEN”.indexOf(‘E’)
12 Considering the statement int a[]={1,5,7,9}; what will be the contents of a[2] at the execution of
a[2]+=a[2]-- + ++a[3]
13 Read the following code and answer the questions given below:
Class TestProg
{
int x,y;
TextProg()
{
x=40;y=50;
}
int add(int z)
{
int c;
c=x+ y+z;
return c;
}
void display()
{
System.out.println(“Sum is”+Add(100));
}
Public static void main(String a[])
{
TestProg T=new TestProg();
T.display();
}
}
Identify : a) local variable b) Method with a return type c) Constructor d) attributes (data members)
14 How many times will the following loop execute? What will be the final value?
int a=5,x=0;
do
{
x=a++ * a;
} while(a<=10);
System.out.println(x);
15 Give the output of the following statements:
Char arr[][]={{‘X’,’Y’’Z’},{‘A’,’B’’C’}};
System.out.println(arr[1][0]);
System.out.println(Character.isLowerCase(arr[0][1]));
16 Name the following:
a) The operator that is used to access the members of a class
b) The wrapper class for primitive data type int
17 Give the output of the following :
int a[]={45,-75,35,63};
for(int i=0;i<a.length-1;i++)
a[i+1]=a[i]+10;
for(int i=0;i<a.length-1;i++)
System.out.println(a[i]);
18 Evaluate the expression when the value of x=5
x=(--x) * (++x) +(x++) -(x--);
19 Write a function prototype in which the method Unit takes an integer array, a character value and returns either true or false.
20 Rewrite the following if else if statements using switch case statements.
if(choice==’A’)
System.out.println(“Basketball”);
else if (choice==’C’)
System.out.println(“Football”);
else
System.out.println(“Incorrect choice”);
21 The following code segment should print “divisible by 5 and 10” , if the value x leaves a remainder zero when divided by 5 and 10. However,
the code has errors. Fix the code so that ist compiles and runs correctly.
if x=sc.nextInteger();
if (x/5==0 && x%10=0)
System.out.println(“Not divisible”);
else
System.out.println(“Divisible by 5 and 10”);
22 The following code should print the letters A to Z in Uppercase. However, the code has some error. Fix the code so that it compiles and
executes correctly.
for(int i=65;i<=87;i++)
{
char ch=i;
System.out.println(ch);
}
23 State any 2 keywords used within the switch block
24 Predict the output of the following code segment
String str=”COMPUTER”;
String str1=”PROGRAM”;
String str2=str.substring(2,7)+Integer.toString(str1.indexOf(‘r’,1));
System.out.println(str2);
25 How many times will the loop execute and what will be the output 26 Consider the two array
int k=5; Int a[]={1,2,3,4,5};
int i=-1; Int b[]={5,4,3,2,1};
while(i++<9) What will be the output if the following statements are
{ executed?
k+=i++; double m=Math.round((int)
} Math.sqrt(a[1]+Math.sqrt(b[1])*Math.min(a[3],b[2]));
System.out.println(k); System.out.println(m);
27 When there is no explicit initialization, what are the default values set for variables in the following cases?
a) Boolean variable b) character variable
28 Ramesh tries to execute the following program segment to find out the area of circle. However the output is obtained is incorrect. How the
program can be modified to get the correct answer? Also state the type of error made by Ramesh.
double radius=8.9;
double pi=3.14;
int area=pi*Math.pow(radius,2);
System.out.println(area);

You might also like