Certainly! Below is a simple Java program that prompts the user to input three double values and then prints them backward.
import java.util.Scanner;
public class ReverseDoubles {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);
// Prompt the user for three double values
System.out.print("Enter the first double: ");
double first = scanner.nextDouble();
System.out.print("Enter the second double: ");
double second = scanner.nextDouble();
System.out.print("Enter the third double: ");
double third = scanner.nextDouble();
// Print the doubles in reverse order
System.out.println("The doubles in reverse order are:");
System.out.println(third);
System.out.println(second);
System.out.println(first);
// Close the scanner
scanner.close();
}
}
How to Run the Program:
- Copy and paste the code into a Java development environment, such as Eclipse, IntelliJ IDEA, or a simple text editor.
- Save the file as
ReverseDoubles.java
. - Compile the program using
javac ReverseDoubles.java
in the terminal. - Run the program with
java ReverseDoubles
and follow the prompts to enter three double values.
This program reads three double values from the user, stores them in variables, and then prints them in reverse order.