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

PracticeQuestions Output

The document contains a series of programming questions related to Java, focusing on output based questions, method behavior, string manipulation, mathematical functions, and control flow. Each question requires the reader to analyze code snippets and predict their outputs, as well as to evaluate expressions and write Java code for specific scenarios. The questions are designed to test understanding of Java syntax, data types, and logic.

Uploaded by

kongk7395
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)
25 views6 pages

PracticeQuestions Output

The document contains a series of programming questions related to Java, focusing on output based questions, method behavior, string manipulation, mathematical functions, and control flow. Each question requires the reader to analyze code snippets and predict their outputs, as well as to evaluate expressions and write Java code for specific scenarios. The questions are designed to test understanding of Java syntax, data types, and logic.

Uploaded by

kongk7395
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

Ouput Based Questions

Q1. What will be the output of the following method for x(5,8)
public void x(int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
System.out.print(a);
System.out.print(b);
}
What is the method computing/solving? What names you give to the method x() so that it’s
name become mnemonic.

Q2. Given the following declarations:


String a=”abc”;
String s=a;
String t;
What is the value of the following expression (assume that there is no error)?
a) s.length();
b) 1+a;
c) “Tomorrow”.indexOf(‘r’);
d) “Tomorrow”.substring(2,4);
e) (a.length()+a).startsWith(“a”);
f) a.substring(1,3).equals(“bc”);

Q3. What is the output of the following program? [2]


public class check
{
public static void change(String nm)
{
nm = “Kush”;
}
public static void main()
{
String name = “Sandeep”;
System.out.println(name);
change(name);
System.out.println(name);
}
}

Q4. What will be the output of the following function? [4]


i) Math.pow(3,0.5) ii) Math.min(-21,-12)
iii) Math.ceil(5.2) iv) Math.floor(2.9)

Q5. Evaluate the following expression: when a=10, b=8 [3]


i) ++a-b– ii) a%b++
iii) a*=b+5
Q6. Write the java expressions for each of the following: [4]
(i) x = e|2x – 4x|
(ii) s=`/sin a + tan-1 a – e2x

Q. 7. Find the output of the following questions. Give the dry run or working. In one line say
what is being computed by the function. [10]

public class output2


{ // if the value of n is 5
public static int unknown(int n)
{
int i,k;
if(n%2==0)
{
i=n/2;
k=1;
}
else
{
k=n;
n–;
i=n/2;
}
while(i>0)
{
k=k*i*n;
i–;
n–;
}
return(k);
}
}

Q8.

public class output3


{
public static void main()
{
int n=5732,result=0;
do
{
result *= 10;
int digit = n%10;
result += digit ;
n = n/10;
}while(n>0);
System.out.println(“Output = ” + result);
}
}
Q9. Find out the output of each of the following programs. Dry run or working is necessary,
(if possible).

public static void main()


{
String x = new String(“AMIT”);
char c; String p=””; int i;
for(i=0;i<x.length();i++)
{
c=x.charAt(i);
p=c+p;
System.out.println(p);
}
}

Q10. Give the output of the following program segment.

public static void abc()


{
int x=1, i=2;
do
{
x*=i;
}while(++i<=5);
System.out.println(x);
}

Q11. Give the output of the following program segment:

public class t100


{
public static void main()
{
int i=1,n=6,f=1;
while(i<=n)
{
f=f*i; i++;
System.out.print(f+” “);
}
}
}

Q12. Give the output of the following program segment:

public class t200


{
public static void main()
{
int i,n=5,s=0;
double f=0;
for(i=n;i>0;i–)
{
s=i*i;
f=(Math.pow(s,2))-i;
System.out.println(f);
}
}
}

Q13. Give the output of the following program segment [3]


String x = new String(“LOYOLA”);
char c; String p=””; int i;
for(i=0;i<x.length();i++)
{
c=x.charAt(i);
p=c+p;
System.out.println(p);
}

Q14. Give the output of the following program segment [4]

public class q4
{
public static void main()
{
String s=”Object”;
int l=s.length();
for(int c=0;c<l;c++)
{
if(Character.isLowerCase(s.charAt(c)))
System.out.print(Character.toUpperCase(s.charAt(c)));
else if(c%22==0)
System.out.print(‘E’);
else
System.out.print(Character.toLowerCase(s.charAt(c)));
}
}
}

Q15.

public class q1 [4]


{
public static void main()
{
int x[]={60,50,30,40},y=3,size=4;
for(int i=size-1;i>=0;i–)
switch(i)
{
case 0:
case 2: System.out.println(y*x[i]);break;
case 1:
case 3: System.out.println(y+x[i]);
}
}
}

Q16. If m=5 and n=2 output the values of m and n after execution in (i) and (ii). [ICSE
2005]

(i) m -= n;

(ii) n = m + m/n;

Q17. What will be the output of the following. if x=5 initially? [ICSE 2005]
(i) 5 * ++x
(ii) 5 * x++

Q18. What is the output of the following? [ICSE 2005]


char c = ‘A’;
short m = 26;
int n = c + m;
System.out.println(n);

Q19. What do the following functions return for: [ICSE 2005]


String x = “hello”;
String y = “world”;
(i) System.out.println((x + y);
(ii) System.out.println((x.length());
(iii) System.out.println((x.charAt(3));
(iv) System.out.println((x.equals(y));

Q20.

int val=500;
int sum;
n=550;
sum=n+val>1750?400:200;

System.out.println("sum is =" +sum);

Q21.

val=1600;
sum=n+val>1750?400:200; //ICSE 2006
System.out.println("sum is =" +sum);
Q22.

a=2;
b=3;
c=9;
int out=a-(b++)*(--c); //ICSE 2007
System.out.println("OUTPUT:" +out);

Q23.

a=2;
b=3;
c=9;
out=a*(++b)%c; //ICSE 2007
System.out.println("OUTPUT:" +out);

You might also like