'F' → Fullscreen
greetUser(String name) that prints
a personalized greeting. main() and call the
method. import java.util.Scanner;
public class Program{ public static void main(String[] args) { Scanner input = new Scanner(System.in);
// Task 1 System.out.println("--- Math Utilities ---");
System.out.print("Enter your name: "); String userName = input.nextLine();
greetUser(userName); }
// Task 1 Method static void greetUser(String name) { System.out.println("Hello, " + name + "!"); System.out.println("Welcome to the Math Utility Program.\n"); }}square(int n) that returns the square
of a number. main(), ask the user for a number, call
square(num), and print the result. import java.util.Scanner;
public class Program{ public static void main(String[] args) {9 collapsed lines
Scanner input = new Scanner(System.in);
// Task 1 System.out.println("--- Math Utilities ---");
System.out.print("Enter your name: "); String userName = input.nextLine();
greetUser(userName);
// Task 2 System.out.print("Enter a number to square: "); int num = input.nextInt();
int result = square(num); System.out.println("The square is " + result + "\n"); }
6 collapsed lines
// Task 1 Method static void greetUser(String name) { System.out.println("Hello, " + name + "!"); System.out.println("Welcome to the Math Utility Program.\n"); }
// Task 2 Method static int square(int n) { return n * n; }}average(double a, double b) that returns
the average of two numbers. randomInRange(int min, int max) to
return a random integer between two values. import java.util.Scanner;
public class Program{ public static void main(String[] args) {17 collapsed lines
Scanner input = new Scanner(System.in);
// Task 1 System.out.println("--- Math Utilities ---");
System.out.print("Enter your name: "); String userName = input.nextLine();
greetUser(userName);
// Task 2 System.out.print("Enter a number to square: "); int num = input.nextInt();
int result = square(num); System.out.println("The square is " + result + "\n");
// Task 3 System.out.print("Enter first number: "); double a = input.nextDouble();
System.out.print("Enter second number: "); double b = input.nextDouble();
double avg = average(a, b); System.out.println("The average is " + avg + "\n");
System.out.print("Enter minimum value: "); int min = input.nextInt();
System.out.print("Enter maximum value: "); int max = input.nextInt();
int random = randomInRange(min, max); System.out.println("Random number between " + min + " and " + max + ": " + random + "\n"); }
12 collapsed lines
// Task 1 Method static void greetUser(String name) { System.out.println("Hello, " + name + "!"); System.out.println("Welcome to the Math Utility Program.\n"); }
// Task 2 Method static int square(int n) { return n * n; }
// Task 3 Methods static double average(double a, double b) { return (a + b) / 2.0; }
static int randomInRange(int min, int max) { return (int)((Math.random() * (max - min + 1)) + min); }}Your program output should look similar to the example below.
Enter your name: AnthonyHello, Anthony!Welcome to the Math Utility Program.
Enter a number to square: 6The square is 36
Enter first number: 8Enter second number: 10The average is 9.0
Enter minimum value: 1Enter maximum value: 10Random number between 1 and 10: 4You may write your reflection answers as comments at the bottom of your code.
Submit your completed .java file and reflection answers
to the appropriate dropbox.