Function name should be problem Function should accept 2 input arguments. The fi
ID: 3830615 • Letter: F
Question
Function name should be problem Function should accept 2 input arguments. The first input argument should be called iterations, the second input argument should be called the number. Function should have 2 output arguments. The first should be called result, and the second should be called loop_counter. The function body should do the following It should create a for loop that will start at 1 and repeat "iterations" times. That is, the input argument called iterations, has a number inside. This number represents how many times the loop should repeat. The variable that is used to initialize your loop array (the thing that determines how many times your loop repeats) should be called loop_counter. Each time the loop repeats, you should add the current value of your loop counter variable to value is currently inside the input argument the_number" and add this answer to whatever is in your output argument called result.Explanation / Answer
FunctionProblem.java :
____________________
import java.util.Scanner;
public class FunctionProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter no.of Iterations and Number:");
int ite = sc.nextInt();
int num = sc.nextInt();
int output = Problem_2(ite,num);
System.out.println("Result is:"+output);
}
public static int Problem_2(int iterations,int the_number){
int result = 0,loop_counter = 0;
for(int i=1;i<=iterations;i++){
loop_counter += the_number;
}
result = loop_counter;
return result;
}
}
Sample Input and Output:
______________________
Enter no.of Iterations and Number:43 78
Result is:3354
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.