diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..a9afb92 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,29 @@ +import java.util.Scanner; + /** * Created by iyasuwatts on 10/17/17. */ public class Main { - public static void main(String[] args){ + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + Scanner input2 = new Scanner(System.in); + System.out.println("Please enter a number."); + int inputNumber = input.nextInt(); + int inputNumber2 = inputNumber; + System.out.println("Would you like the sum or the product of this number? Press 1 for sum or 2 for product."); + while (true){ + int choice = input.nextInt(); + if (choice == 1) { + Sum.find(inputNumber, inputNumber2); + break; + } else if (choice == 2) { + Product.find(inputNumber, inputNumber2); + break; + } else { + System.out.println("Please enter 1 or 2 to select sum or product."); + } + } } } diff --git a/src/main/java/Product.java b/src/main/java/Product.java new file mode 100644 index 0000000..a57b05e --- /dev/null +++ b/src/main/java/Product.java @@ -0,0 +1,9 @@ +public class Product { + public static void find(int numberInput, int numberInput2) { + for (int count = 1; count < numberInput2; count++) { + numberInput = numberInput * count; + } + System.out.println("The product of all the numbers from 1 to " + numberInput2 + " is " + numberInput); + + } +} diff --git a/src/main/java/Sum.java b/src/main/java/Sum.java new file mode 100644 index 0000000..19bef44 --- /dev/null +++ b/src/main/java/Sum.java @@ -0,0 +1,11 @@ +public class Sum { + + + public static void find(int numberInput, int numberInput2) { + for (int count = 0; count < numberInput2; count++) { + numberInput += count; + } + System.out.println("The sum of all the numbers from 1 to " + numberInput2 + " is " + numberInput); + + } +} \ No newline at end of file