Question 3

a) Write the output
int x=0;
do
{
if(x<3)
{
x+=2;
System.out.println(x);
continue;
}
else
{
System.out.println(++x);
break;
}
}
while(x<10);
b) Write the output
class box
{
int width;
int height;
int length;
int volume;
void volume(int height, int length, int width)
{
volume = width*height*length;
}
}
class Prameterized_method
{
public static void main(String args[])
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(3,2,1);
System.out.println(obj.volume);
}
}
c) Write the output
class equality
{
int x;
int y;
boolean isequal()
{
return(x == y);
}
}

class Output
{
public static void main(String args[])
{
equality obj = new equality();
obj.x = 5;
obj.y = 5;
System.out.println(obj.isequal());
}

Answers

a)

0 < 3    x= 2 print 2  continue

2< 3      x = 4  print 4  continue

4<3 false  x=5  print 5 break

b)

3*2*1   = 6

c)

true

This entry was posted in Term 1. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *