Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB 4 [1] What output is produced by the following program? (2pt) public class ParameterMystery { public static void main(String[] args) { int a =

LAB 4

[1] What output is produced by the following program? (2pt)

public class ParameterMystery { public static void main(String[] args) { int a = 10, b = 6, c = -2; parammystery(a, b, c); parammystery(c, 5, a); parammystery(a + b, b + c, c + a);

System.out.println("a: " + a + ", b: " + b + ", c: " + c + " in main()"); } public static void parammystery(int c, int a, int b) { b -= 3; c = a + 5; a = a - b; System.out.println(b + " ^ " + c + " = " + a);

System.out.println("a: " + a + ", b: " + b + ", c: " + c + " in parammystery()"); } }

[2] Write a program which contains a method named printMatrix() that accepts two parameters: the number of rows and columns not greater than 9, respectively. Your method should print each row starting at the number of each row, with each subsequent column number within a fixed width, 5 and right-aligned. For example, the call printMatrix(3,6) should produce exactly, the following output: (2pt)

// bbbb_bbbb_bbbb_bbbb_bbbb_bbbb_ (b: blank) : This is for your convenience.

Row 1 : 1 2 3 4 5 6

Row 2 : 2 3 4 5 6 7

Row 3 : 3 4 5 6 7 8

O Parameters and Boolean Return

[3] Write a program with a method named isBothEvenNumber() that accepts a non-negative two integer values as parameters and returns boolean true or false value. For example, the call isBothEvenNumber(50, 99) should return false. isBothEvenNumber(50, 100) should return true. (2pt)

O Loops

[4] Assume that you have a variable called count that takes on the values 1, 2, 3, 4, and so on. You are to formulate expressions in terms of count that will yield the following sequences. For example, if you wanted to create the sequence 3, 5, 7, 9, 11, 13, ..., you should immediately note that each number in the sequence can be obtained by adding 2 to the preceding number. Note also that the expression (count * 2) would produce the sequence 2, 4, 6, 8, 10, 12, .... Finally, we need only shift the expression (count * 2) by the amount needed to produce the first number of the sequence (+1). It follows that the needed expression is (count * 2) + 1 for the sequence 3, 5, 7, 9, 11, 13, ... in terms of count. (2pt)

Using the same procedure, fill in the table below, indicating an expression that will generate each sequence.

Sequence

Expression

3, 9, 15, 21, 27, 33,

33, 21,9, -3, -15, -27,

-9, -5, -1, 3, 7, 11,

This can be submitted by a word document or a program with comments producing the result sequence from the count.

[5] Task (2pt) : Use nested for loops statements to draw empty boxes of any character (input from user). The boxes have the same number of rows and columns (input from the user; valid range: 5 to 21). Test for errors in input (including type) using while loop.

SAMPLE OUTPUT:

Do you want to start(Y/N): y

How many characters in a row? n

Not an integer! Try again! How many characters in a row? fgfgfg

Not an integer! Try again! How many characters in a row? 7.6

Not an integer! Try again! How many characters in a row? 34

ERROR! Valid range 5 - 21. How many characters in a row? 7

What character? k

kkkkkkk

k k

k k

k k

k k

k k

kkkkkkk

Do you want to continue(Y/N): y

How many characters in a row? y

Not an integer! Try again! How many characters in a row? 9

What character? #

#########

# #

# #

# #

# #

# #

# #

# #

#########

Do you want to continue(Y/N): n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

What role does the GL department play in the conversion cycle?

Answered: 1 week ago

Question

What is the general process for selecting expatriates?

Answered: 1 week ago