Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/Product.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
11 changes: 11 additions & 0 deletions src/main/java/Sum.java
Original file line number Diff line number Diff line change
@@ -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);

}
}