













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














What |\is |\the |\output |\of |\this |\program? int |\sum |= |\1; |
System.out.println("Welcome |\to |\the |\adding |\machine!"); |
while(sum |< |\10) |
{ |
|\sum |+= |\sum; |
|\System.out.println(sum); |
} |- |\CORRECT |\ANSWERS |\✔✔Welcome |\to |\the |\adding |
machine! |{Unit |\2} 2 4 8 16 What |\is |\the |\output |\of |\this |\for |\loop? for(int |\i |= |\0; |\i |< |\100; |\i |+= |\2) |
{ |
|\System.out.println(i); |\
} |- |\CORRECT |\ANSWERS |\✔✔The |\even |\numbers |\from |\ 0 |\to |
98, |\inclusive |{Unit |\2} What |\is |\the |\proper |\syntax |\to |\initialize |\a |\double |\called |
temperature |\to |\have |\the |\value |\70.4? |- |\CORRECT |
ANSWERS |\✔✔double |\temperature |= |\70.4; |{Unit |\2} Which |\of |\the |\following |\is |\not |\a |\primitive |\type? |- |\CORRECT |
ANSWERS |\✔✔String |{Unit |\2} What |\in |\this |\code |\segment |\could |\potentially |\cause |\a |\bug |
in |\our |\program? String |\myString |= |\readLine("What |\is |\your |\name?"); |
if |(myString |== |"Karel") |
{ |
|\System.out.println("Hi |\Karel!"); |
} |
else |
{ |
|\System.out.println("You're |\not |\Karel!"); |
} |- |\CORRECT |\ANSWERS |\✔✔Comparing |\Strings |\with |== |
instead |\of |\the |.equals |\method. |{Unit |\2}
|\x |= |\99; |
|} |
} else |
{ |
|\x++; |
} |
y |= |\x |+ |\y; |- |\CORRECT |\ANSWERS |\✔✔x |= |\ 99 y |= |\ 199 {Unit |\2} Which |\expression |\is |\true? |- |\CORRECT |\ANSWERS |\✔✔!false ||| |!true |{Unit |\2} What |\will |\this |\program |\print |\if |\the |\value |\of |\grade |\is |\80? if(grade |> |\90) |
{ |
System.out.println("A"); |
} |
else |\if(grade |> |\80) |
{ System.out.println("B"); |\
else |\if(grade |> |\70) |
{ |
System.out.println("C"); |
} |- |\CORRECT |\ANSWERS |\✔✔C |{Unit |\2} What |\is |\the |\value |\of |\x |\after |\this |\code? int |\x |= |\5; |
x |= |\10; x |= |\4; |- |\CORRECT |\ANSWERS |\✔✔ 4 |{Unit |\2} What |\will |\this |\code |\output? if(true |&& |\true |&& |\false) |
{ |
System.out.println("Hello |\Karel"); } |
if(true |&& |\ 4 |== |\ 2 |+ |\2) |
{ |
System.out.println("Second |\if |\statement!"); |
} |- |\CORRECT |\ANSWERS |\✔✔Second |\if |\statement! |{Unit |\2}
CORRECT |\ANSWERS |\✔✔double |\myDouble |= |(double) |\1/4; |
{Unit |\2} What |\is |\the |\value |\of |\myInteger |\after |\this |\line |\of |\code? int |\myInteger |= |(int) |\5.6; |- |\CORRECT |\ANSWERS |\✔✔ 5 |
{Unit |\2} What |\is |\the |\result |\of |\this |\expression? 4 |+ |\ 8 |* |\ 3 |/ |\ 4 |+ |\ 5 |% |\ 2 |- |\CORRECT |\ANSWERS |\✔✔ 11 |{Unit |
2} What |\is |\the |\output |\of |\the |\following |\lines? int |\x |= |\24; |\System.out.println("The |\total |\is |" |+ |\x |+ |\x); |- |
CORRECT |\ANSWERS |\✔✔The |\total |\is |\ 2424 |{Unit |\2} How |\many |\times |\will |\the |\loop |\execute? int |\i |= |\0; |
while(i |< |\50) |
{ |
|\System.out.println(i); |
|\i |+= |\10; |
} |- |\CORRECT |\ANSWERS |\✔✔ 5 |{Unit |\2}
What |\is |\the |\result |\of |\this |\expression? 5 |+ |\ 2 |/ |\ 3 |+ |\ 1 |- |\CORRECT |\ANSWERS |\✔✔ 6 |{Unit |\2} What |\output |\will |\be |\produced |\by System.out.println("Hello"); System.out.println("Karel"); |- |\CORRECT |\ANSWERS |
✔✔Hello Karel {Unit |\2} What |\will |\the |\code |\segment |\output? for |(int |\m |= |\5; |\m |> |\0; |\m--) |
{ |
|\for(int |\n |= |\m; |\n |> |\0; |\n--) |
|{ |
|\System.out.print("*"); |
|} |
|\System.out.print("\n"); |
} |- |\CORRECT |\ANSWERS |\✔✔***** |
**** |
*** |
** |\
What |\kind |\of |\error |\does |\this |\method |\cause? public |\void |\buggyMethod(String |\x) |
{ |
|\for(int |\i |= |\0; |\i |<= |\x.length(); |\i++) |
|{ |
|\System.out.println(x.substring(i, |\i+1)); |
|} |
} buggyMethod("BUG"); |- |\CORRECT |\ANSWERS |\✔✔Runtime |
Error: |\String |\index |\out |\of |\range |{Unit |\3} What |\will |\this |\method |\call |\print |\to |\the |\screen? public |\void |\numberMadness(double |\myDouble) |
{ |\int |\myInt |= |(int) |\myDouble; |
|\String |\myString |= |""; |
|\while(myInt |!= |\0) |
|{ |
|\myString |= |\myInt |% |\ 10 |+ |\myString; |
|\myInt |/= |\10; |
|} |
|\System.out.println(myString); |\
numberMadness(12345) |- |\CORRECT |\ANSWERS |\✔✔ 12345 |
{Unit |\3} What |\is |\wrong |\with |\this |\method |\definition? public |\String |\outputString(String |\input) |
{ |
|\System.out.println(input); |
} |- |\CORRECT |\ANSWERS |\✔✔Improper |\return |\value |{Unit |
3} What |\are |\parameters? |- |\CORRECT |\ANSWERS |\✔✔The |
formal |\names |\given |\to |\the |\data |\that |\gets |\passed |\into |\a |
method. |{Unit |\3} What |\does |\this |\method |\call |\return? public |\int |\doubleInt(int |\x) |
{ |
|\x |* |\2; |
} doubleInt(5); |- |\CORRECT |\ANSWERS |\✔✔This |\method |\is |
improperly |\written. |{Unit |\3}
|\int |\count |= |\0; |
|\while(true) |
|{ |
|\if(count |== |\10) |
|{ |
|\System.out.println("You |\are |\locked |\out!"); |
|\return; |
|} |
|\if(readLine("Password?").equals("secret")) |
|{ |
|\System.out.println("Welcome!"); |\return; |
|} |
|\count++; |
|} |
} What |\would |\this |\method |\call |\output? public |\int |\myMethod(int |\num) |
{ |
|\while(num |/ |\ 10 |>= |\10) |
|{ |\
|\num |/= |\10; |
|} |
|\return |\num; |
} myMethod(830) |- |\CORRECT |\ANSWERS |\✔✔ 83 |{Unit |\3} Why |\do |\we |\use |\methods |\in |\Java? |- |\CORRECT |\ANSWERS |
✔✔To |\make |\code |\easier |\to |\understand; |\To |\avoid |\repeated |
code; |\To |\simplify |\code |{Unit |\3} What |\does |\this |\method |\call |\output? public |\double |\doubleOrNothing(double |\myDouble) |
{ |
return |(double) |(int) |\myDouble |* |\2; |
} doubleOrNothing(9.9); |- |\CORRECT |\ANSWERS |\✔✔18.0 |
{Unit |\3} What |\does |\this |\method |\call |\output? public |\int |\trickyMethod(int |\x, |\int |\y) |
{ |
|\int |\sum |= |\0; |
|\while |(x |<= |\10) |\
What |\will |\this |\method |\call |\print |\to |\the |\screen? public |\static |\void |\someMethod(int |\a, |\String |\b, |\int |\c) |
{ |
System.out.println(b |+ |" |" |+ |\a |+ |", |" |+ |\c); |
} someMethod(9,"Mar", |\1250) |- |\CORRECT |\ANSWERS |\✔✔Mar |\9, |\ 1250 |{Unit |\3} What |\is |\a |\return |\value? |- |\CORRECT |\ANSWERS |\✔✔The |
value |\that |\a |\method |\outputs. |{Unit |\3} What |\is |\a |\method? |- |\CORRECT |\ANSWERS |\✔✔A |\procedure |
that |\is |\defined |\by |\the |\user. |{Unit |\3} What |\will |\this |\method |\call |\output? public |\int |\myMethod(boolean |\x, |\boolean |\y) |
{ |
|\if(!x) |
|{ |
|\if(y) |
|{ |
|\return |\1; |\
|\else |
|{ |
|\return |\0; |
|} |
|} |
|\else |
|{ |
|\return |-1; |
|} |
} myMethod(false,false) |- |\CORRECT |\ANSWERS |\✔✔ 0 |{Unit |
3} What |\does |\void |\mean? |- |\CORRECT |\ANSWERS |\✔✔Void |
means |\that |\a |\method |\returns |\no |\value. |{Unit |\3} What |\will |\this |\method |\call |\output? public |\int |\mysteryMethod(String |\x, |\char |\y) |
{ |
|\int |\z |= |\1; |
|\for(int |\i |= |\0; |\i |< |\x.length(); |\i++) |\
someMethod(9990) |- |\CORRECT |\ANSWERS |\✔✔true |{Unit |
3} What |\will |\this |\method |\call |\print? public |\void |\patternGrid(int |\rows, |\int |\columns, |\char |
symbol) |
{ |
|\for(int |\m |= |\0; |\m |< |\rows; |\m++) |
|{ |
|\for(int |\n |= |\0; |\n |< |\columns; |\n++) |
|{ |
|\System.out.print(symbol); |
|} |
|\System.out.println(); |
|} |
} patternGrid(3,4,'#'); |- |\CORRECT |\ANSWERS |\✔✔#### |\
{Unit |\3}
Write |\a |\method |\that |\will |\ask |\for |\user |\input |\until |\user |
inputs |\the |\String |"no". |\Allow |\the |\user |\to |\input |\any |
capitalization |\of |\the |\String |"no" |("no", |"No", |"NO", |"nO") |
Also, |\have |\the |\method |\return |\the |\number |\of |\loops.