1 A B C D: Find Output

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Q1

class hcf
{
public static void main(String arg[])
{
long n1,n2;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number 1");
n1= ? 1 ? ;
System.out.println("Enter number 2");
n2= ? 1 ? ;
long result= ? 2 ? ;
System.out.println("Hcf of two numbers = "+result);
}
static long hcfCal(long a,long b)
{ long temp;
while (b > 0)
{
temp = b;
b=?3?
a = temp;
}
return ? 4 ?;
}
}

1 a b c d
sc.NextLong(); sc.nextLong(); sc.nextInt(); Non of them

2 a b c d
hcfCal(n1,n2) hcfCal(int n1,int n2) long hcfCal(n1,n2) hcfCal(int n1,n2)

3 a b c d
a / b; a % b; b%a b/a

4 a b c d
b a temp b%a

Q2)

class esskay1
{
int highest(int a,int b)
{
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
return a;
}
}

find output a b c d
highest(33 , 21) 12 3 9 0
What is the above function doing a b c d
highest(a,b) Finding highest of two Finding lcm of two Finding hcf of two Finding difference of two

What is the output produced by the following lines of program code?

char x, y;
x = 'y';
System.out.println(x);
y = 'z';
System.out.println(y);
x = y;
System.out.println(x);

Write the output:

char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);

Write the output of the following statement:

System.out.println("A picture is worth \t \"A thousand words.\" ")

Predict the output of the following Java program snippet:

System.out.println("India got independence");


System.out.println("on");
System.out.println("15th August,1947");

Predict the output of the following Java program snippet:

System.out.println("My name is ");


System.out.print("Kunal Kishore");
System.out.println("I am a student of Class X");

Predict the output of the following Java program snippet:

System.out.print("The factorial of 5 is");


System.out.println("120");

Predict the output of the following Java program snippet:

System.out.println("This is my first Java program");


System.out.print("Display the message:");
System.out.print("Have fun!!!");

Give output of the following function definition and also write the mathematical operation they carry out:

void test3(char c)
{
System.out.println( (int) c);
}

if 'm' is passed to c.

Give output of the following function definition and also write the mathematical operation they carry out:

void test4(String x, String y)


{
if(x.compareTo(y) > 0)
System.out.println(x);
else
System.out.println(y);
}

if "AMIT" and "AMAN" are passed to the function.

Give output of the following function definition and also write the mathematical operation they carry out:

void test1(int n)
{
for(int x=1; x<=n; x++)
if(n%x == 0)
System. out.println(x);
}

if 12 is passed to n.

Give output of the following function definition and also write the mathematical operation they carry out:

void test2(int a, int b)


{
while( a != b)
{
if ( a > b)
a = a — b;
else
a = b — a;
}
System.out.println(a);
}
if 4 and 17 are passed to the function.

Give the output of the following Java program snippet based on nested loops:

int y,p;
for (int x=1; x<=3; x++)
{
for (y=1; y<=2; y++)
{
p = x * y;
System.out.print(p);
}
System.out.println( );
}

Give the output of the following Java program snippet based on nested loops:

int x,y;
for(x=1; x<=5; x++)
{
for(y=1; y<x; y++)
{
if(x == 4)
break;
System.out.print(y);
}
System.out.println( );
}

Give the output of the following Java program snippet based on nested loops:

int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
System.out.print((char) b);
System.out.println( );
}

Give the output of the following Java program snippet based on nested loops:

int i,j;
first:
for (i=10; i>=5; i--)
{
for (j= 5; j<=i; j++)
{
if (i*j <40)
continue first;
System.out.print(j);
}
System.out.println( );
}

Give the output of the following Java program snippet based on nested loops:

int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
System.out.print(j);
System.out.println();
}
VIEW ANSWER

Predict the output of the following Java program code snippet:

int m=3,n=5,p=4;
if(m==n && n!=p)
{
System.out.println(m*n);
System.out.println(n%p);
}
if((m!=n) || (n==p))
{
System.out.println(m+n);
System.out.println(m-n);
}

int a=1,b=2,c=3;
switch(p)
{
case 1: a++;
case 2: ++b;
break;
case 3: c--;
}
System.out.println(a + "," + b + "," +c);

Predict the Output of the given snippet, when executed:

int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
{
System.out.println((m+n));
System.out.println((m—n));
}
if((a==1)&&(b==1))
{
System.out.println((m*n));
System. out.println((m%n));
}

Predict the Output of the given snippet, when executed:

int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
System.out.println(r);
}
else
{
c=a/b;
System.out.println(c);
}

Predict the output and the number of times the loop runs:

class Test {
public static void main(String args[]) {
int i;
for(i=0;i<5;i++)
System.out.println(i-i*i);
}
}

Give the output of the following:

Math.sqrt(Math.max(9,16))

System.out.println(Math.floor(-4.7));
System.out.println(Math.max(Math.ceil(14.55),15.5));
System.out.println(Math.rint(-9.4)+Math.sqrt(9.0));
System.out.println(Math.ceil(3.4)+Math.pow(2,3));
System.out.println(Math.sqrt(Math.min(42.5,42.25)));
System.out.println(Math.rint(-99.4));
System.out.println(Math.floor(-0.88));
System.out.println(Math.max(-77.66, -87.45));
System.out.println(Math.round(-18.51));
System.out.println(Math.sqrt(10.24));

String P = "20", Q ="19";


int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);

char c = 'B';
int i = 4;
System.out.println(c+i);
System.out.println((int)c+i);

String s= "7";
int t =Integer.parseInt(s);
t=t+1000;
System.out.println(t);

char c = 'B';
int i = 4;
System.out.println(c+i);
System.out.println((int)c+i);

char ch = 'x'; int n = 5;


n = n + (int)ch;
char c = (char)n;
System.out.println((char)((int)c-26));

String a="10", b="20";


int x=Integer.parseInt(a);
int y=Integer.valueOf(b);
System.out.println(x+y);
System.out.println(a+b);

You might also like