CSC 1301 Lab #10 PART 1. · Please explain the following examples related to how to pass any parameter into the methods. Example 1: 1 public class SingleParameter{ 2 public static void main(String[]...

1 answer below »
Please provide screenshot of final output together with code in one word document for three problems


CSC 1301 Lab #10 PART 1. · Please explain the following examples related to how to pass any parameter into the methods. Example 1: 1 public class SingleParameter{ 2 public static void main(String[] args) { 3 int x = 17; 4 doubleNumber(x); 5 System.out.println("x = " + x); 6 System.out.println(); 7 8 int number = 42; 9 doubleNumber(number); 10System.out.println("number = " + number); 11 } 12 13 public static void doubleNumber(int number) { 14 System.out.println("Initial value = " + number); 15 number *= 2; 16 System.out.println("Final value = " + number); 17 } 18 } Output: Initial value = 17 Final value = 34 x = 17 Initial value = 42 Final value = 84 number = 42 Example 2: public class DoubleParameter { public static void main(String[] args) { writeChars('=', 20); System.out.println(); for (int i = 1; i <= 10;="" i++)="" {="" writechars('="">', i); writeChars(' ', 20 - 2 * i); writeChars('<', i);="" system.out.println();="" }="" }="" public="" static="" void="" writechars(char="" ch,="" int="" number)="" {="" for="" (int="" i="1;" i=""><= number;="" i++)="" {="" system.out.print(ch);="" }="" }="" }="" output:="==================="> <>> <>>> <>>>> <>>>>><>>>>>><>>>>>>><>>>>>>>><>>>>>>>>><>>>>>>>>>>< question 1: question 2: question 3: page 2 of 10 question="" 1:="" question="" 2:="" question="" 3:="" page="" 2="" of="">
Answered 1 days AfterMar 27, 2021

Answer To: CSC 1301 Lab #10 PART 1. · Please explain the following examples related to how to pass any...

Arun Shankar answered on Mar 29 2021
154 Votes
Example 1
On line 4, the function doubleNumber() is invoked with 17 as the argument. Inside the fun
ction doubleNumber(), 17 gets copied to the local variable ‘number’.
Then Initial value = 17 is printed on line 14. ‘number’ now becomes 34 on line 15. Then, Final value = 34 is printed on line 16. Back in main, on line 5, x = 17 is printed because the value of the local variable x is unchanged.
The same happens in line 9 - Within the doubleNumber() function, the local variable ‘number’ is now set to 42, printed, then doubled, and printed again. Back in the main() function, 42 is printed because the value of ‘number’ in main() is unchanged.
Example 2
The writeChars(char ch, int number) function expects two arguments - a character, and a number. The function prints the character ‘number’ times. Within the main, we are printing ten lines. On each line, there are 20 characters. On the ith line, we will print the > character i times, then fill...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here