Java Unit 5 Functions and Parameters

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How many return values come out of the function sum? function sum(first, second){ var result = first + second; return result; } 0 1 2 3

1

What is printed when the following code is run? function doubleNumber(x){ return 2*x; } function start(){ var y = 4; var doubledY = doubleNumber(y); var result = doubleNumber(doubledY); print(result); } 4 8 16 64

16

How many parameters go into the function sum? function sum(first, second){ var result = first + second; return result; } 1 0 3 2

2

What is the output of the following code? function start(){ var x = 5; quadrupleNumber(x); } function quadrupleNumber(x){ var quadX = 4 * x; println(quadX); } 10 15 20 no output, there is a syntax error

20

What is printed by the following code? function printNumbers(first, second, third){ println(first); println(second); println(third); } function start(){ var middle = 5; printNumbers(4, middle, 6); } 456 4 5 6 4middle6 4 middle 6

4 5 6

Why do we write functions? Make our code easier to understand by giving a readable name to a group of instructions Avoid writing repeated code Make our code reusable All of the above

All of the above

If we want to draw a circle using our helpful drawCircle function at position (300, 400) with a radius of 40 and color blue, which is the correct function call? As a reminder, here's the function header for drawCircle: function drawCircle(radius, color, x, y) drawCircle(300, 400, 40, Color.blue); drawCircle(300, 400, Color.blue, 40); drawCircle(40, Color.blue, 300, 400); drawCircle(radius, color, x, y);

drawCircle(40, Color.blue, 300, 400);

What are the parameters of the printNumbers function? function printNumbers(first, second, third){ println(first); println(second); println(third); } first, second, third x, y, z println printNumbers

first, second, and third

Do functions need to have parameters? yes no

no

Which statement allows us to return values from functions? break return if function

return

function quadrupleNumber(x){ var quadX = 4 * x; println(quadX); } What is the parameter of the function quadrupleNumber? x println quadX none

x

In the following code snippet: function addTen(x){ var ten = 10; var result = x + ten; return result } function double(x){ var result = 2*x; return result; } What are the local variables of the function double? x, result, and ten x and result only x only result

x and result


Ensembles d'études connexes

Arch 3 History Test - Charles Rennie Mackintosh and the Glasgow School

View Set

Project Management Exam 2 Fall 2021

View Set

PPT 28 - Intellectual Property Rights: Copyrights

View Set

Chapitre 2: QC *Nouvelle-France ~1608-1663-1754

View Set

Trigonometry - Solving Trig Equations

View Set

Chapter 8 Health Insurance Basics

View Set

CISCO Cybersecurity Essentials v1.1 - Final Quiz, Part A

View Set