import java.util.Scanner; public class MethodsParamExample { // Calling prn meth
ID: 3703981 • Letter: I
Question
import java.util.Scanner;
public class MethodsParamExample
{
// Calling prn method
public static void good(int num)
{
for(int count=0; count < num; count++)
{
prn();
}
}
// Printing out Good Morning
public static void prn()
{
System.out.println("Good Morning!");
}
public static int sum(int num1, int num2, int total)
{
total = num1 + num2;
return total;
}
public static void main(String[] args)
{
int total = 10;
Scanner sc = new Scanner(System.in);
System.out.println("How many times do you want to print 'Good Morning'?");
int printNum = sc.nextInt();
System.out.println("You asked to print out 'Good Morning' "+printNum+" times. ");
good(printNum);
System.out.println("That's all Folks!");
int finalTot = sum(4,5,total);
System.out.println("The value of Total is: "+total);
System.out.println("The value of Total is: "+finalTot);
}
}
What is the order of execution or statement for this coding?
For example
//Step 1, Step 4, Step 7 for Line 3. If it executes more than once, put the steps on the same line with a comma.
//Step 2 for Line 7
Explanation / Answer
ANSWER: Here first of all your question is not clear that what steps you are telling but here I am explaining the execution flow of this code if you have any problem then you can comment or like this.
EXecution flow:
Execution will start from main here it is asking for how many times you print good morning after that inputting a value it calls a method good () then it goes into the good method, in the good method in for loop it is calling the prn() method.After that, you call a method sum () which returns you the sum of the numbers which you passed in it and it will store in the variable finalTot. After that, you are printing the Total variable which is not present in the code it will give you the error and next statement you are printing the finalTot that will give you the sum.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.