Professional Documents
Culture Documents
1 A B C D: Find Output
1 A B C D: Find Output
1 A B C D: Find Output
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
char x, y;
x = 'y';
System.out.println(x);
y = 'z';
System.out.println(y);
x = y;
System.out.println(x);
char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);
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:
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:
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
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);
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));
}
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);
}
}
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));
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);