2024_Programming_Training_D.../CS3 - Challenge Solution/Main.java

38 lines
1.5 KiB
Java

import java.util.Scanner;
/*
CS3 Challenge Solution
Original Challenge Description: Build a program that requests
three numbers from the user, and performs a math operation on
them and prints the result.
*/
public class Main {
public static void main(String[] args) {
//Start with setting up System.in through a Scanner
Scanner scan = new Scanner(System.in);
//Grab three values from the user, all of them are doubles
System.out.print("Value 1: ");
double firstValue = scan.nextDouble();
System.out.print("Value 2: ");
double secondValue = scan.nextDouble();
System.out.print("Value 3: ");
double thirdValue = scan.nextDouble();
//Print out the operation being performed. Two things of note here,
//the first thing in the println is an empty string, this helps Java to know
//that it's supposed to be combining Strings, not attempting to do regular
//mathematical addition.
//The second thing is that we have the actual math at the end of the println
//statement wrapped in parenthesis. This helps to ensure that Java treats
//that as a math operation, and separates it from all of the combining of Strings
//that is going on outside the parenthesis.
System.out.println("" + firstValue + " / " + secondValue + " - " + thirdValue + " = " + (firstValue / secondValue - thirdValue));
//Close the scanner, because good practice.
scan.close();
}
}