(Solved) : 1 20 Points Write Java Program Asks User Input Positive Integer N First Create Array Size Q34272594 . . .
1. (20 points)
Write a Java program that asks the user to input a positiveinteger n first, then create an array of size n. Fill n randomintegers between 5 and 555, inclusively, into the created array.Output the sum of all the integers in the array and the average ofall the integers in the array.
2. (10 points)
Find the output of the following Java program and explain youranswer.
public class NO2HW1
{
public static void main(String args[])
{
int min = 100;
int a = 10;
int b = 20;
min_method(a, b, min);
System.out.println(min);
}
public static void min_method(int n1, int n2, int min)
{
if (n1 < n2)
min = n1;
else
min = n2;
System.out.println(min);
}
}
3. (10 points)
Find the output of the following Java program and explain youranswer.
class Circle
{
double radius;
Circle(double r) { radius = r; }
}
public class NO3HW1
{
public static void main(String args[])
{
Circlecircle1 = new Circle(10.0);
Circlecircle2 = new Circle(20.0);
System.out.println(“Before invoking swap: ” +
” nthe radius of circle1 is ” + circle1.radius +
” nthe radius of circle2 is ” + circle2.radius);
swap(circle1, circle2);
System.out.println(“nAfter invoking swap: ” +
” nthe radius of circle1 is ” + circle1.radius +
” nthe radius of circle2 is ” + circle2.radius);
}
public static void swap(Circle x,Circle y)
{
System.out.println(“nBefore swap: ” +
” nthe radius of circle x is ” + x.radius +
” nthe radius of circle y is ” + y.radius);
Circle temp = x;
x = y;
y = temp;
System.out.println(“nAfter swap: ” +
” nthe radius of circle x is ” + x.radius +
” nthe radius of circle y is ” + y.radius);
}
}
Expert Answer
Answer to 1 20 Points Write Java Program Asks User Input Positive Integer N First Create Array Size Q34272594 . . .
OR