jName______Practice

ExamI ComputerScience119

Inquestions1-5circlethebestanswerinthemultiplechoice.

1.Thefollowingstatementwilldeclareavariable,numb,thatwillbeusedtostore the weight of a candy bar to the nearest tenth of a gram.

a.integergrams;

b.intgrams;

c.double grams;

d.real grams;

2.Theoperationsperformedbyaclassarecalled

a.objects.

b.methods.

c.syntax.

d.identifiers.

3.CompiledJavaprogramscanonlyberanoncomputerswith:

a.aJVM.

b.abrowser.

c.microphone.

d.anIDE

4.AstandaloneJavaprogramis:

a.aMachineLanguageprogram.

b.anApplet.

c.anApplication.

d.anexampleofHardware.

5.HowcanyoucompileaJavaprogramineclipse?

6.CirclethenamesinthislistthatfollowtheconventionusedbyJavaprogrammerstonamevariables:(10points)

something Something balance200099balloons voting#machine

7.WriteaJavastatementtoprintthemessage"LettheGamesBegin!"onthescreen.

8.WhatcharactersareusedtobeginandendaclassinJava?

9.RewritethismathequationasaassignmentstatementinJava:

10.WhatLinuxcommanddoyouusetochange directories intoadirectorynamedmyjava.

11.WhatisthevalueofthisJavaexpression: 6 – 2/3+8

12.WritethelinenecessarytocreateaScannerthatcanbeusedforinput. Assume the Scanner class has already been imported.

13.UsetheScanneryoucreatedin#12toinputan integer into a variable,cars.

14.Whatistheoutputofthisprogram?

//Programtellnumberofcookies

importjava.text.*;

publicclassDozens

{

publicstaticvoidmain(String[]args)

{

intcookies;

intdozen;

cookies=58;

dozen=58/13;

System.out.println(dozen+"DozenCookies");

}

}

15.Correcttheerror.Linenumbersaretohelpyoufindtheerror.

1//programtofigureaveragespeedonatrip

2//fromD.C.toN.Y.

3

4publicclassTravel2

5{

6 publicstaticvoidmain(String[]args)

7 {

8 System.out.print("Thespeedonatrip");

9 System.out.println("fromD.C.toN.Y.is"+233/7-2);

10 }

11}

ErrorMessage:

Travel2.java:9:operator-cannotbeappliedtojava.lang.String,int

System.out.println("fromD.C.toN.Y.Is"+233/7-2);

16.Rewritethisprogramsothatitisingoodprogrammingstyle.(10points)

publicclass houston

{publicstaticvoidmain

(String[]args){

System.out.print

("Three...");System.out.print(

"Two...");System.out.println("One...");

System.out.println("Houston,wehaveaproblem.");}}

17.Writeajavaprogramtoinputa the base and the height of a triangle then output it's area.

(10points)