Skip to content

I completed this project finally #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
50 changes: 48 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
/**
* Created by iyasuwatts on 10/17/17.
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args){
public static void main(String[] args) {

// TO DO:
// Ask for an input value of integer n
// Create a scanner to store to integer n and string choice of sum or product
// Incorporate a switch statement for string choice
// Input from the switch statement decides the method that will execute
//

//-------------------------------------------------------------------------------------------------------------------

// THIS IS 1 SCANNER WITH 2 INPUTS
Scanner sn = new Scanner(System.in);

System.out.println("Enter an integer: ");
String nAsAString = sn.nextLine();
int n = Integer.parseInt(nAsAString);



System.out.println("Enter an option of \"sum\" or \"product: \"");
String choice = sn.nextLine();

int theSum = 0;
int theProduct = 1;


if (choice.equalsIgnoreCase("sum")) {
for (int i = 0; i <= n; i++) {
theSum += i;
}

System.out.println(theSum);
} else if (choice.equalsIgnoreCase("product")) {
for (int i = 1; i <= n; i++) {
theProduct *= i;
}

System.out.println(theProduct);

} else {

System.out.println("You did not submit a valid choice");
}

}
}
}