0% found this document useful (0 votes)
59 views

mcq-4,5,6 Java Dry-Run Programs Answers

1. This document contains 4 questions related to Java programming. Question 1 has multiple choice questions testing Java concepts like identifiers, data types, operators, and packages. Question 2 has code snippets to analyze and write the dry run/output for. Question 3 asks to create a menu driven program to input a number and calculate factorial or print digits vertically. Question 4 asks to write a program to calculate discounts on laptop purchases based on purchase amount ranges. 2. The document contains 4 questions on Java programming concepts like data types, operators, packages, loops, methods, conditionals, arrays etc. It asks to choose the right option for multiple choice questions, analyze and write dry runs for code snippets, create a menu driven program to

Uploaded by

anshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

mcq-4,5,6 Java Dry-Run Programs Answers

1. This document contains 4 questions related to Java programming. Question 1 has multiple choice questions testing Java concepts like identifiers, data types, operators, and packages. Question 2 has code snippets to analyze and write the dry run/output for. Question 3 asks to create a menu driven program to input a number and calculate factorial or print digits vertically. Question 4 asks to write a program to calculate discounts on laptop purchases based on purchase amount ranges. 2. The document contains 4 questions on Java programming concepts like data types, operators, packages, loops, methods, conditionals, arrays etc. It asks to choose the right option for multiple choice questions, analyze and write dry runs for code snippets, create a menu driven program to

Uploaded by

anshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

FM:-40 Q.1.

Choose the correct answer:-[1X10=10M]


a)An/a___________ that we use in a program can be composed of any combination of letters,digits,the underscore
character(_) and the dollar sign($).[char,constants,identifier,variable]
b)The byte type can be assigned a larger range of numbers than the int type.[true/false]
c)if int x=5,y=10,z=11; then what will be the value of double c, when c=x*y+z/2;[53.0,55.02,55.0,55.03]
d)The package(s) used for input output is –[io,util,lang,both io and util]
e)___________ is the collection of related classes and interfaces having common functionality.
[class,package,array,polymorphism]
f)Choose the odd one.[/,++,*,%]
g)Which of the following is not mandatory in a variable declaration?[semicolon,identifier,assignment,data type]
h)When the operators have the same priority , they are evaluated from__________in the order they appear in the
expression.[right to left,left to right,any of the order,depends on the compiler]
i)Which of the following is not Java primitive type.[byte,float,character,long]
j)The name given to the character set of java.[UNICODE,ASCII,IISCODE,FSI]
Q.2.Do as directed:-[2X5=10M]
a)Write java expression:- a) b) Write the dry-run and output:- c)Write the dry-run and output:-
−b+ √ b −4 ac int p=15,q=12,s; for(int i=1;i<=5;i++)
2
b) s=p/q*++p%(++p%--q); {System.out.println(“Diwali”);brea
2a
System.out.println(s); k;}
√ a2 +b2 S=15/12*15%(16%11) Diwali
4
x S=1*15%(16%11)
a)double x=-b+Math.sqrt(b*b- S=15%(5)=0
4*a*c)/(2*a);
b)double
c=Math.sqrt(a*a+b*b)/Math.pow(x,
4);
d) rewrite into multiple branching e)Write the dry-run:-
statement:- int i=1;
if(inpu==5) while(i<=10){i++;System.ot.println(i);i+
{val=num*25-20; +;}
System.out.println(num+val); 2
} 4
else if(inpu==10) 6
{val=num*25-20; 8
System.ou.println(val-num);} 10
else (As i is getting incremented twice only
System.out.println(val/num); the even digits will be printed
switch(inpu)
{case 5:val=num*25-
20;System.out.println(num+val);bre
ak;
case 10:val=num*25-
20;System.out.println(val-
num);break;
default:System.out.println(val/
num);}
Q.3.Write a menu driven program to do the following:-[10]
1-to input a number and print its factorial.[for eg-if number is 6-factorial is 1X2X3X4X5X6=720]
2-to input a number and print its digits vertically.
For eg:- 345 output
3
4
5
import java.util.*;
class p
{public static void main()
{Scanner br=new Scanner(System.in);
int ch,n,f=1,n1,r=0,d;
System.out.println(“enter choice");ch=br.nextInt();
switch(ch)
{case 1:System.out. println(“enter a number") ;
n=br.nextInt();
for(int i=1;i<=n;i++)
{f=f*i;}System.out.println(f);break;
case 2:System.out.println(“enter a number");
n=br.nextInt();
while(n!=0){d=n%10;r=r*10+d;n=n/10;}
while(r!=0){d=r%10;System.out.println(d);r=r/10;}
}}

Q.4. An electronic shop has announced the following seasonal discounts on the purchase of laptops.[10]
Purchase Amount   Discount
0-25000                     0.0%
25001-50000            5.0%
50001-100000         7.5%
>100000                    10.0%
Input the amount for 10 customers , calculate and print the discount for each and the total discount given for all the
customers .
import java.util.*;
class p
{public static void main()
{Scanner br=new Scanner(System.in);int I,p;
double d=0.0d,t=0.0d;
for(i=1;i<=10;i++)
{System.out.println(“enter purchase amount");
p=br.nextInt();
if(p>=0&&p<=25000)
d=0.0;
else if(p>25000 &&p<=50000)
d=0.05*p;
else if(p>50000&&p<=100000)
d=0.075*p;
else
d=0.10*p;
System.out.println(p+” “+d);
t=t+d;
}
System.out.println(t);}}

You might also like