Uploaded by Emy Alinsod

OOP 2022 Programming Assignment 1

advertisement
Programming Assignment 1
Write/type your answers(complete JAVA program) after each of the
following questions. Turn -in (Upload/attached) PDF copy of your
assignment via MS Teams Assignment.
Name: _____________________________________
Section:___________________
1. Complete the code segment to find the perimeter and area of a circle
given a value of radius.(5 points)
You should use Math.PI constant in your program. If radius is zero or less
than zero then print ” please enter non zero positive number “.
Code:System.out.println(2*Math.PI*radius);
System.out.print(radius*Math.PI*radius);
2. Complete the code segment to find the largest among three numbers
x,y, and z. You should use if-then-else construct in Java. (5 points)
Code:if (_____________)
System.out.print(x);
else if (____________)
System.out.print(y);
else
System.out.println(z);
4. Consider First n even numbers starting from zero(0).Complete the code
segment to calculate sum of all the numbers divisible by 3 from 0 to n.
Print the sum.(5 points)
Code:int a=-2;
for(int i=0;i<n;i++)
{
a=a+2;
if(____________)
sum+=a;
}
System.out.print(sum);
5. Complete the code segment to check whether the number is an
Armstrong number or not.(5 points)
Armstrong Number:
A positive number is called an Armstrong number if it is equal to the sum of
cubes of its digits for example 153 = 13+53+33, 370, 371, 407, etc.
Code:int num=n;
while(num>0)
{
int r=___________;
result+=__________;
num/=_______;
}
if (result==n)
System.out.print(1);
else
System.out.print(0);
6. Complete the code segment to find the highest mark and average mark
secured in “s” number of subjects. (5 points)
Code:int sum=0,max=0;
for(int x=0;x<arr.length;x++)
{
if(________________)
max=_____________;
sum+=arr[i1];
}
mark_avg=__________________;
System.out.println(max);
System.out.print(mark_avg);
Download