Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete program that accepts three integers from the user and output th

ID: 3645122 • Letter: W

Question

Write a complete program that accepts three integers from the user and output the largest of their
three absolute values. For example, largest value of (7, -2, -11) is 11.

Requirements

1. You must interact with the user to ask the numbers.
2. You need to ask the user how many sets of numbers does she/he has.
3. You must write a method called largestAbsValue that accepts the three numbers and
returns the largest absolute value.
4. You must use the Scanner class
5. Use the method from the Math class to find the absolute value.
6. You program must run as long as the user wants to therefore you need to ask the user.

7. Below is a sample output that will help you more.

What is your name? Gita
Hello Gita How many sets of numbers do you have ? 3
Enter three integer numbers seperated by spaces 2 -100 -200
The largets absolute value of 2,-100,-200 is 200
Enter three integer numbers seperated by spaces 4567 -957464 23
The largets absolute value of 4567,-957464,23 is 957464
Enter three integer numbers seperated by spaces 45 97 0
The largets absolute value of 45,97,0 is 97

Explanation / Answer

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

public class Ints {

public static void main(String[] args){

Scanner in = new Scanner(System.in);

System.out.println("Hi! What is your name?");

String name = in.nextLine();

System.out.println("Hello " + name + ", how many sets of numbers will you input?");

int numSets = in.nextInt();

for(int i=0; i<numSets; i++){

ArrayList<Integer> ints = new ArrayList<Integer>();

System.out.println("Enter three integers, seperated by spaces (hit enter when done): ");

for(int j=0; j<3; j++){

ints.add(Math.abs(in.nextInt()));

Collections.sort(ints);

}

System.out.println("The largest absolute value is: " + ints.get(ints.size()-1));

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote