Écrire un programme en Java qui permet d'afficher le plus grand de trois entiers saisis…
- User
Écrire un programme en Java qui permet d'afficher le plus grand de trois entiers saisis au clavier.
- Assistant
Voici un exemple de programme en Java qui permet d'afficher le plus grand de trois entiers saisis au clavier :
import java.util.Scanner; public class PlusGrand { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Entrez le premier entier : "); int entier1 = scanner.nextInt(); System.out.print("Entrez le deuxième entier : "); int entier2 = scanner.nextInt(); System.out.print("Entrez le troisième entier : "); int entier3 = scanner.nextInt(); int plusGrand = entier1; if (entier2 > plusGrand) { plusGrand = entier2; } if (entier3 > plusGrand) { plusGrand = entier3; } System.out.println("Le plus grand entier est : " + plusGrand); } }Dans ce programme, nous utilisons la classe
Scannerpour lire les entiers saisis par l'utilisateur. On demande à l'utilisateur d'entrer les trois entiers successivement, puis nous comparons ces entiers entre eux pour trouver le plus grand à l'aide de la structure conditionnelleif. Finalement, nous affichons le plus grand entier obtenu. - User
translate it in englich please
- Assistant
Here's a program in Java that allows you to display the largest of three integers entered from the keyboard:
import java.util.Scanner; public class LargestNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the first integer: "); int int1 = scanner.nextInt(); System.out.print("Enter the second integer: "); int int2 = scanner.nextInt(); System.out.print("Enter the third integer: "); int int3 = scanner.nextInt(); int largest = int1; if (int2 > largest) { largest = int2; } if (int3 > largest) { largest = int3; } System.out.println("The largest integer is: " + largest); } }In this program, we use the
Scannerclass to read the integers entered by the user. We ask the user to enter the three integers successively, and then we compare these integers with each other to find the largest using theifconditional statement. Finally, we display the largest obtained integer. - User
Create a program BestBikeCustomers.java for BestBike Customer Management. The program uses the class Customer that contains the following attributes. CustomerID, Name, Surname, Age, City, PostalCode, Street, Phone, E-Mail The Customer Management program creates two customers, initializes the attributes with test data and prints out the customer data/attributes on the screen. short solution
- Assistant
- User
Create a program SimpleMethod.java with method maxMinSumSquareRt() that takes three double values as arguments, calculates the sum of the largest and smallest value and returns the square root of the sum. In your method you can use methods of the class Math. Run (main method) the method maxMinSumSquareRt(double a, double b, double c) in the same class with three parameters of your choice and print out the result on the command
- Assistant
Here's the program SimpleMethod.java that includes the maxMinSumSquareRt() method:
public class SimpleMethod { public static void main(String[] args) { double a = 5.2; double b = 4.3; double c = 6.1; double result = maxMinSumSquareRt(a, b, c); System.out.println("Result: " + result); } public static double maxMinSumSquareRt(double a, double b, double c) { double largest = Math.max(Math.max(a, b), c); double smallest = Math.min(Math.min(a, b), c); double sum = largest + smallest; double squareRoot = Math.sqrt(sum); return squareRoot; } }In this program, the maxMinSumSquareRt() method takes three double values as arguments: a, b, and c.
Inside the method, we use the Math.max() method to find the largest value among a, b, and c. Then, we use the Math.min() method to find the smallest value.
Next, we calculate the sum of the largest and smallest value. Finally, we use the Math.sqrt() method to calculate the square root of the sum and return the result.
In the main method, we call the maxMinSumSquareRt() method with three parameters of our choice (5.2, 4.3, and 6.1) and print out the result on the console.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.