Write a Java program that asks the user to input a positive integer n first, then create
Question:
Write a Java program that asks the user to input a positive integer n first, then create an array of size n. Fill n random integers between 5 and 555, inclusively, into the created array. Output the sum of all the integers in the array and the average of all the integers in the array.
Find the output of the following Java program and explain your answer.
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);
}
}
Find the output of the following Java program and explain your answer.
class Circle
{
double radius;
Circle(double r) { radius = r; }
}
public class NO3HW1
{
public static void main(String args[])
{
Circle circle1 = new Circle(10.0);
Circle circle2 = 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);
}
}