Skip to content
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
25 changes: 25 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
/**
* Created by iyasuwatts on 10/17/17.
*/
import java.util.*;
public class Main {

public static void main(String[] args){
int result=0;
Scanner input = new Scanner(System.in);
System.out.println(" please enter a number and I willl give you the sum or product of numbers between 1 and the " +
"number you put");
int inputNumber = input.nextInt();
input.nextLine();
System.out.println("would you like a sum or a product?");
String inputAnswer = input.nextLine();
if(inputAnswer.equalsIgnoreCase("Sum")){
for(int i = 1;i<=inputNumber;i++){
result+=i;
}
}else{
result+=1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should have checked the input for Product here. Also you should rework to ask sum or product before asking for the number.

for(int j =1;j<=inputNumber;j++){
result*=j;
}
}
if(inputAnswer.equalsIgnoreCase("sum")){
System.out.println("The sum of the integers from 1- "+ inputNumber+ " is "+ result);
}else {
System.out.println("The product of the integers from 1- "+ inputNumber+ " is "+ result);
}

}

}