• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 27 páginas
Examen

D286: Java Fundamentals

Document preview thumbnail
Vista previa 3 fuera de 27 páginas

D286: JAVA FUNDAMENTALS

Vista previa del contenido

D286: JAVA FUNDAMENTALS
Main()m-manswers--
Wheremamprogrammbeginsmexecutingmstatementsmcontainedmwithinmbracesm{}.

System.out.print()m-manswers--
Outputsmanmitemmonmthemscreen,mstartingmatmthemscreenmcursor'smpresentmlocation,m
andmmovingmthemcursormaftermeachmoutputmitem.

System.out.println()m-manswers--
Printsmanmitemmandmthenmmovesmthemcursormtomthemnextmlinem(ie:mnewline).

importmjava.util.Scanner;m-manswers--
Specificmimportmcodemplacedmatmthemtopmofmamfilemtomenablemthemprogrammtomgetmin
put

Scannermscnrm=mnewmScanner(System.in);m-manswers--
Themstatementmthatminstantiatesmamnewmscannermobjectminmthemvariablem"scnr"msomsy
stemminputmcanmbemparsed.

scnr.nextInt();m-manswers--
Themstatementmthatmretrievesmthemsystem'smnextmintegermvalueminput.m

Itmismthemvariablem"scnr"mcallingmthismscannermclassmmethodmtomreadmintegermvaluesm
fromminputmmadempossiblemafterm"scnr"misminstantiatedmwithmamnewmscannermclassmo
bject.

"desiredmtext"m-manswers--Syntaxmformstringmliterals,mwhichmismtextminmdoublemquotes

System.out.println("Wagemis:m"m+mwage);m-manswers--
Thismexamplemshowsmhowmthem"+"msymbolmismusedmtomoutputmmultiplemitemsmusingm
onemoutputmstatement.

\nm-manswers--
Thismismthemsyntaxmformthemnewlinemcharacter,manmalternativemtom"println",mthoughmno
tmusedmoftenmformpracticalmpurposes.

//mThismismamcommentm-manswers--Thismismthemsyntaxmformwritingmamsingle-
linemcommentmthatmcommonlymappearsmaftermamstatementmonmthemsamemline.

/**

,Thismismamcomment
**/m-manswers--Thismismthemsyntaxmformwritingmammulti-
linemcomment,malsomcalledmamblockmcomment.

Whitespacem-manswers--
Thismismblankmspacem(spacemandmtabmcharacters)mbetweenmitemsmwithinmamstatemen
tmandmblankmlinesmbetweenmstatementsm(calledmnewlines).

Amcompilermignoresmmostmofmthismandmismusedmtommakemamprogrammmoremreadable.

intmnumValue;m-manswers--
Thismismanmexamplemsyntaxmformdeclaringmanmintegermvariablemwithmthemidentifierm"nu
mValue".mInmgeneral,manymidentifiermthatmismnotmamreservedmwordm(ie:mkeyword)mcan
mbemusedmtomnamemamvariable.mNotmhowmthismexamplemismusingmlowerCamelCase.


numValuem=m8;m-manswers--
Thismismanmexamplemsyntaxmformanmassignmentmstatement,mwhichmassignsmanmintege
rmliteralmtomamdeclaredmvariable.

intmnumValuem=m100;m-manswers--
Thismismanmexamplemsyntaxmforminitializingmanmintegermvariable,mwhichmassignsmanmin
tegermliteralm(ie:minitialmvalue)matmthemsamemtimemthemvariablemismdeclared.

+,m-,m*,m/m-manswers--
Syntaxmformthemaddition,msubtraction,mmultiplication,mandmdivisionmarithmeticmoperator
s,mrespectively.

(),munarym-,m*m/m%,m+m-m-manswers--
Thesemfourmoperatormcategoriesmaremlistedmfirstmtomlastmaccordingmtomprecedencemrul
esmformarithmeticmoperators.

+=,m-=,m*=,m/=,m%=m-manswers--
Thesemaremthemfivemspecialmoperatorsmknownmasmcompoundmoperators,mwhichmallmpr
ovidemamshorthandmwaymtomupdatemamvariable

doublemmilesTravel;m-manswers--
Thismismanmexamplemsyntaxmformdeclaringmamvariablemthatmcanmstoremamfloating-
pointmnumber.

scnr.nextDouble();m-manswers--Amscannermmethodmthatmreadsmamfloating-
pointmvaluemfromminput,mwhichmcanmbemassignedmtomamdoublemvariable.

Infinity,m-Infinitym-manswers--
Javamoutputsmthesemwhenmamusermdividesmamnonzeromfloating-
pointmnumbermbymzero.

, Notmamnumberm(NaN)m-manswers--Ifmthemdividendmandmdivisorminmfloating-
pointmdivisionmarembothm0,mthemdivisionmresultsminmthismoutput.

System.out.printf("%.2f",mmyFloat);m-manswers--
Thismexamplemshowsmthemsyntaxmformcontrollingmthemnumbermofmdecimalmplacesmwhe
nmprintingmamfloating-
pointmnumber.mInmthismcase,m'printf'mformfloat,m'.2'mmeansmtomtwomdecimalmplaces,man
dm'myFloat'mismanmexamplemvariablemwheremthemdecimalmplacemmanipulationmismappli
ed

Math.PIm-manswers--
Javamprovidesmthismtomholdmthemfirstm15mdigitsmofmthemirrationalmmathematicalmconsta
ntmpim(π).

6.02e23m-manswers--Thismismanmexamplemsyntaxmofmamfloating-
pointmliteralmusingmscientificmnotationmwheremthememprecedesmthempower-of-
10mexponent.

finalmdoublemSPEED_OF_SOUNDm=m761.207;m-manswers--
Thismismanmexamplemsyntaxmformdeclaringmamconstantmvariablem(ie:mfinalmvariable).mN
otemthemusemofm'final'mtompreventmmodificationmandmthemusemofmuppermcasesm&munde
rscoresmformidentifiability.

Math.m-manswers--
ThemsyntaxmforminvokingmthemMathmclass,mamJavamstandardmpackagemthatmallowsmab
outm30mmathmmethodsmtombemcalled.

sqrt(x),mpow(x,my),mabs(x)m-manswers--
Themsyntaxmofmthreemcommonmmathmmethodsmtominvokemsquaremroot,mpower,mandma
bsolutemvaluemformamgivenmvalue,mrespectively.mThesemmustmbemappendedmtom'Math.'
mtomwork.


5m/m2m=m2mvsm5.0m/m2.0m=m2.5m-manswers--
Thesemtwomdivisionsmshowmhowmthemresultmdependsmonmwhethermormnotmtheminvolve
dmvaluesmaremintegersmormfloating-point.mIntegermdivisionmneglectsmanymremainder.

randNumm%m10m-manswers--
Thismexamplemyieldsmamrandommnumbermbetweenm0mandm9,mmadempossiblembymthem
modulomoperator.mNotemthatm0mismpossible,mnotm10.

(randNumm%m11)m+m20m-manswers--
Thismexamplemyieldsmamrandommnumbermbetweenm20mandm30,mmadempossiblembymth
emmodulomoperatormandmthenmaddingm20mtomthemresult.

0.504m*m316m=m159.264m-manswers--
Thismexamplemshowsmhowmcalculatingmanymintegermwithmamfloating-

Información del documento

Subido en
29 de abril de 2025
Número de páginas
27
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$17.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
575
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes