From 6d4442e5fb093075db69a8172e2854242c619d52 Mon Sep 17 00:00:00 2001 From: Kibret Tecle Date: Wed, 7 Feb 2018 13:17:11 -0500 Subject: [PATCH] complete SumOrProduct --- src/main/java/Main.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1dbc0cb..3397286 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -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; + 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); + } } + }