Quiz1 Answers
1) c
2) c
3) d
4) d
5) b
6) a
7) c
8) b
9) b,d
10) c
JAVA WEEK1 :Q1
/*Complete the code segment to find the perimeter and area of a circle given a value of radius. You should use [Link] constant in
your program. If radius is zero or less than zero then print " please enter non zero positive number ". */
import [Link];
public class Question3 {
public static void main(String[] args)
{
Scanner s = new Scanner([Link]);
double radius= [Link]();
double perimeter;
double area;
if(radius<=0)
[Link](" please enter non zero positive number");
else
{
perimeter =[Link]*(radius*radius);
area=2*[Link]*radius;
[Link](perimeter);
[Link](area);
}
}
}
Java Week 1:Q2
Complete the code segment to find the largest among three numbers x, y, and z. You should use if-then-else construct in Java.
import [Link];
public class Exercise1_2 {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
int x = [Link]();
int y = [Link]();
int z = [Link]();
int result = 0;
//Use if...else ladder to find the largest among 3 numbers and store the largest number in a variable called result.
if(x>y && x>z)
result=x;
else if(y>x && y>z)
result=y;
else
result=z;
[Link](result);
}
}
Java Week 1:Q3
import [Link];
public class Question3 {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n=[Link]();
int sum=0;
int i=0;
int count=0;
while(count<=n)
{
if(i%2==0 && i%3==0)
sum=sum+i;
i=i+2;
count++;
}
[Link](sum);
}
}
Java Week 1:Q4
Complete the code segment to check whether the number is an Armstrong number or not.
import [Link];
public class Question3 {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n=[Link]();
int result=0;
int sum=0;
int temp=n;
while(n!=0)
{
sum=sum+(int)[Link]((n%10),3);
n=n/10;
}
if(sum==temp)
result=1;
else
result=0;
[Link](result);
}
}
Java Week 1:Q5
Complete the code segment to find the highest mark and average mark secured by Hari in "s" number of subjects.
import [Link];
public class Exercise1_5{
public static void main(String[] args) {
Scanner input = new Scanner([Link]);
double mark_avg;
int result;
int i;
int s;
//define size of array
s = [Link]();
//The array is defined "arr" and inserted marks into it of integer type.
int[] arr = new int[s];
for(i=0;i<[Link];i++)
{
arr[i]=[Link]();
}
result=arr[0];
int sum=arr[0];
for(i=1;i!=s;i++)
{
sum=sum+arr[i];
if(arr[i]>result)
result=arr[i];
}
mark_avg=sum/s;
[Link](result);
[Link](mark_avg);
}}