13 views

Uploaded by jocansino4496

fhfdfdfgfg

- CPCS202_Lab3g
- The Secret Book of FRC LabVIEW v0.2
- ExcelFunctionsFormulaeeBook.pdf
- OBIEE Variables
- Verilog Basics 4 Blocks CondStatement Loops
- Palm M3Chapter4
- groovyBC.pdf
- Starting Out With Programming Logic & Design - Chapter2_Input, Processing, And Output
- subtitles about
- Lab-09
- Computer science homwork
- Learn PHP In A Day
- Control Structures
- Curriculum Ranorex Certificate
- 0864-introduction-to-programming-using-fortran-9520032008.pdf
- Supervisor CheatSheet
- Pseudo Code
- Programming in R
- vbscript tutorial
- 0163 Cat a Maths Paper b Sample

You are on page 1of 11

1. Write Java statement that does the following. a. Declare a variable named distance that is used store a real number. Answer double distance; b. Declare and initialize a variable named age with a value of 30. Answer int age = 30; c. Declare three integer variables ! " and z in one Java statement. Answer int ! "! z; #. Assume the variables a = #! b = $! and c = %. &ndicate b" circling the ' or ( if each of the following condition is true or false. a = = $ )) b * # 1 += b ,, c +=3 +-a * #. T T T ( ( (

3. Write an if statement that dis/la"s the message 0 'he number is valid1 if the variable s/eed is within the range 0 through #00. Answer if - s/eed *0 ,, 2 #00. 3"stem.out./rintln-0'he number is valid1.; $. Write an if statement that dis/la"s the message 0'he number is invalid1 if the variable s/eed is outside the range 0 through #00. Answer if-s/eed 2 0 )) s/eed *#00. 3"stem.out./rintln-0'he number is invalid1.; 4. Write an if5else statement that assigns #0 to the variable " if the variable 100. 6therwise! it should assign 0 to the variable ". Answer if - * 100. " = #0; else is greater than

" = 0; %. 7se the following if 8 else if statement to answer 9uestions a! b and c. if = = 0. 3"stem.out./rintln-0 else if - * 10. 3"stem.out./rintln-0 else if - 2 4 ,, * 0. 3"stem.out./rintln-0 else 3"stem.out./rintln-0 is 01.; is greater than 101.; is less than 41.; is negative1.;

a. What is the out/ut if Answer is greater than 10 b. What is the out/ut if Answer is less than 4 c. What is the out/ut if Answer is negative

is 30:

is $:

is 510:

;. <ow man" times will 0<ello World1 be /rinted in the following /rogram segment: int count =1; while -count 2= 4. =3"stem.out./rintln-0<ello World1.; count>>; ? Answer 4 times @. Write a for loo/ that dis/la"s "our name 10 times. Answer for-int n = 0; n2 10; n>>. 3"stem.out./rintln-0John1.;

A. Write a com/lete Java /rogram with the following re9uirementsB a. Define a method sum#Cumbers with two /arameters named num1 and num#. 'he method returns the sum of num1 and num#. b. Dall the function sum#Cumbes in the main method. Eass two values 10 and #0 to the function sum#Cumbers. Dis/la" the returned value from the function sum#Cumbers. Answer im/ort Fava .swing.G; /ublic class test =/ublic static void main-3tring HI args. = int total; total = sum#Cumbers-10!#0.; 3"stem.out./rintln-0'he sum is 0 > total.; ? /ubic static int sum#Cumbers-int num1! int num#. =int sum; sum = num1 >num#; return sum; ?

10. Write a com/lete Java /rogram with the following re9uirementsB a. Define a method called showJessage that dis/la"s a message 0<ave great holida"s1 b. Define a the main method that called showJesssage method 10 times using a for loo/. Answer im/ort Fava .swing.G /ublic class test =/ublic static void main-3tring HI args. = for -int n = 0; n 2 10; n>>. showJessage- .; ? /ublic static void showJessage- . = 3"stem.out./rintln-0<ave great holida"s1.;

? ?

11. &ntialize a one dimensional arra" called D with the following valuesB 10! $! 3$! %;! @A and #4. Answer int DH I = = 10! $! 3$! %;! @A! #4?; 7sing the arra" D above! answer the following 9uestionsB a. What is the value of DH3I; Answer %; b. 7se a for loo/ to dis/la" all the elements in the arra" D Answer for-int n = 0; n24; n>>. 3"stem.out./rintln-DHnI.;

c. 7se a for loo/ to iterate the arra" D in order to find the smallest element. Answer int smallest = DH0I; for-int n = 1; n 2 4; n >>. if - smallest * DHnI. smallest = DHnI; 1#. Assume that arra" A and K are defined belowB int AH4I==10!#0!30!$0!40?; int KHI = new intH4I; a. H4 /ointsI Write Java statements that co/" the arra" A to the arra" K. <intB use a for loo/. Answer for-int = 0; 24; >>. KH I = AH I; b. H4 /ointsI Write Java statements that calculates the average of all elements in the A arra" using a for loo/. Assign the average to a variable name avg. Answer int sum = 0! average; for-int = 0; 2 4; >>.

sum = sum > A H I; avg = sum L4; 13. Write a com/lete Java /rogram that creates a one dimensional arra" called num with the following valuesB 10!34!$%!%;!A@!#0!%; and $4. 'he /rogram then accumulates onl" the even values in the arra" num and dis/la"s the accumulated value. im/ort Fava .swing.J6/tionEane; /ublic class 3um = /ublic static void main-3tring argsHI. = int numHI = =10!34!$%!%;!A@!#0!%;!$4?; int sum =0; for-int i = 0; i2 @;i>>. if-numHiIM# == 0. sum = sum > numHiI; 3"stem.out./rintln-N3umB N > sum.; 3"stem.e it-0.; ? ? 1$. Write a com/lete Java /rogram that meets the following re9uirementsB a. Dreate a method called calculate3ales. 'he methods acce/ts two arguments. 1st argumentB 9uantit" 5 t"/e integer #nd argumentB /rice/erunit 8 t"/e double 'he method calculates and returns the sale where sales = /rice/erunit times 9uantit". b. Write the main method that asOs the user to enter 9uantit" and /rice/erunit! calls the method calculate3ales and then dis/la"s the sales. Answer im/ort Fava .swing.G; /ublic class 'est =/ublic static void main -3tring HI args. = 3tring s; int 9; double /rice!sales; s = J6/tionEane.show&n/utDialog-NPnter /rice /er unitN.; /rice = Double./arseDouble-s.; s = J6/tionEane.show&n/utDialog-NPnter 9uantit"N.; 9 = &nteger./arse&nt-s.; sales = calculate3ales-9!/rice.; 3"stem.out./rintln-N3alesB N > sales.;

?LLend main /ublic static double calculate3ales-int 9uantit"! double /riceEer7nit. =double sales; sales = /riceEer7nitG9uantit"; return sales; ?LLend method ?LLend class 14. What is the out/ut /roduced b" the following: int n = 10; while- n * 0. =3"stem.out./rintln-n.; n = n 53; ? Answer 10 ; $ 1 1%.. Donvert the following while loo/ to a for loo/B int count = 0; while-count>> 2 40. =3"stem.out./rintln-NAN.; ? Answer for-int count = 0; count 240; count>>. 3"stem.out./rintln-NAN.; 1;. Write a for loo/ that dis/la" the following set of numbersB 0! 10! #0! 30! $0! 40 . . . 1000 Answer for-int i=0; i 2=1000; . = 3"stem.out./rintln-i > N! N.; i = i > 10; ? or

for-int i=0; i 2=1000; i = i > 10. 3"stem.out./rintln-i > N! N.; 1@. Donvert the following while loo/ to a for loo/B int count = 14; while- count55 * 4. =3"stem.out./rintln-1A1.; ? Answer for-int count =14; count * 4; count55. 3"stem.out./rintln-1A1.; 1A. Write a com/lete Java /rogram that dis/la"s the smallest value of the following #5D arra"B 10 5 2 12 4 4 1 ! " ! 5

Answer im/ort Fava.util.G; /ublic class 'est =/ublic static void main-3tringH I arg. = 3canner in/ut = new 3canner-3"stem.in.; int AHIHI = ==10! 4! #!1#?!=$! A! 1! 3?! = $! @! 3! 4??; LLDetermine the smallest value in the arra" int smallestQalue = AH0IH0I; for-int r = 0; r2 A.length; r>>. for-int c=0; c2AHrI.length; c>>. if-AHrIHcI 2 smallestQalue. smallestQalue = AHrIHcI; 3"stem.out./rintln-smallestQalue.; ?LLend method ?LLend class

#0. Draw a Ra/tor flowchart that reads ten integer numbers and dis/la" the smallest and largest of the in/uts.

#1. Draw a Ra/tor flowchart that dis/la"s a table showing the numbers 1 through 10 and their s9uares. (or the out/ut s"mbol! "ou are allowed to use once in "our solution. 6ut/ut sam/leB

1 # 3 $ 4 % ; @ A 10

1 $ A 1% #4 3% $A %$ @1 100

##. H; /ointsI Dom/lete the Java code fragment below b" filling in blanOs. for-int i = 1; ##########; i=i>1. = for-int; $ %###### ;###########.

3"stem.out./rint-$.; 3"stem.out./rintln-.; ? &f "ou fill in blanOs correctl"! "our code fragment should /roduce the following out/utB 1 1# 1#3 1#3$ 1#3$4 1#3$4% 1#3$4%; 1#3$4%;@ 1#3$4%;@A NOTEB 'he method print does not move the cursor to the first column of the ne t line! but method /rintln does. Answer for-int i = 1; i&10; i=i>1. = for-int $%1; $&%i ;$% $'1. 3"stem.out./rint-$.; 3"stem.out./rintln-.; ? C(i)ica* T+in,ing E-e(cises 1. <ow man" different license /lates are available if each /late contains a se9uence of three letters followed b" three digits: Answer #% #% #% 10 10 10 = 1;!4;%!000

#. A student can choose a com/uter /roFect from one of three lists. 'he three lists contain 10! #0! 4 /ossible /roFects! res/ectivel". Co /roFect is more than one list. <ow man" /ossible /roFects are there to choose from: Answer 10 > #0 > 4 = 34

3. What is the /robabilit" that when two dice are rolled! the sum of numbers on the two dices is ;: Answer 'here are si successful outcomes! namel"! -%!1.! -1!%.! -#!4.! -4!#.!-3!$.!-$!3.. 'here are a total of 3% e9uall" outconme when two dices are rolled. 'he /robabilit" that seven comes u/ when two fair dice are rolled is %L3% = 1L%. $. &n the discrete mathematics class ever" student is a maFor in com/uter science or mathematics! or both. 'he number of students having com/uter science as a maFor -/ossibl" along with mathematics. is #4; 'he number of students having mathematics as a maFor -/ossibl" along with com/uter science. is 13; and the number of students maForing in both mathematics and com/uter science is @. <ow man" students are in this class: Answer 'he nunmber of students in this class = #4 > 13 5 @ = 30

- CPCS202_Lab3gUploaded byEmanoAce
- The Secret Book of FRC LabVIEW v0.2Uploaded byHieu LE
- ExcelFunctionsFormulaeeBook.pdfUploaded byAkhila Sankar
- OBIEE VariablesUploaded byBharathidhasan Subramani
- Verilog Basics 4 Blocks CondStatement LoopsUploaded byAhmad Shdifat
- Palm M3Chapter4Uploaded byramu reddy
- groovyBC.pdfUploaded bytoolpost
- Starting Out With Programming Logic & Design - Chapter2_Input, Processing, And OutputUploaded byAndrew Carts
- subtitles aboutUploaded byJay Riddle
- Lab-09Uploaded bytulalit008
- Computer science homworkUploaded byKIKI
- Learn PHP In A DayUploaded byRaglean Cristian
- Control StructuresUploaded byHitesh Kar
- Curriculum Ranorex CertificateUploaded by5ong
- 0864-introduction-to-programming-using-fortran-9520032008.pdfUploaded bysampannkumar
- Supervisor CheatSheetUploaded byByaruhanga Franklin
- Pseudo CodeUploaded byLloydGeuelSantiago
- Programming in RUploaded byJulie Finch
- vbscript tutorialUploaded byapi-278351473
- 0163 Cat a Maths Paper b SampleUploaded bySujeet Suman
- Lecture_4_Nov_28_2016Uploaded byarshad ali
- MATLAB guideUploaded byhelloocean
- ch03Uploaded byAbhiram Shaji
- SimplicityUploaded byapi-3701357
- falseUploaded byPablo Camacho
- MC0066 SET 1 FinishedUploaded byjunaidahmedsiddiqui
- Delete FunctionUploaded bysuchi vedha
- DELETEfunction1.docUploaded bysuchi vedha
- dummy.docUploaded bysuchi vedha
- PrerequisiteUploaded byMalimbz

- Programming in VB.NETUploaded byRohitKumarBirla
- BLA 10 - Designing Combinational Logic Circuit Using Karnaugh MappingUploaded byjocansino4496
- pe03_itm103Uploaded byjocansino4496
- 209929488 Combinational Logic Design 1 PPTUploaded byjocansino4496
- Curriculum 2011Uploaded byjocansino4496
- Computer Engineering CurriculumUploaded byjocansino4496
- Topic 5_Karnaugh MapUploaded bysafuan_alcatra
- Music ProjUploaded byjocansino4496
- Lab Exercise 6 QueuesUploaded byjocansino4496
- Good Moral (Repaired)Uploaded byjocansino4496
- Introduction to ProgrammingUploaded byjocansino4496
- Lecture01 Objectorientedprogramming 130120010815 Phpapp01 (1)Uploaded byjocansino4496
- ITPROGX3 - Practical Examination No. 1Uploaded byjocansino4496
- ITPROGX2 - Functions - UpdatedUploaded byjocansino4496
- DigitalLab ECCE 2008Uploaded byjocansino4496
- 13-javascript-introduction-120708105031-phpapp01.pptUploaded byjocansino4496
- 4 - PointersUploaded byjocansino4496
- Padre Pio Prayer SheetUploaded byMae Dela Torre Borla
- Itprog1 Assignment Cover Page TemplateUploaded byjocansino4496
- AC11_sol.pdfUploaded byRishikeshMalviya
- Feu Eac Lab Activity 7 c Arrays2Uploaded byjocansino4496
- Dtr Sir CecogoUploaded byjocansino4496
- 221_activeLearningPHPUploaded byjocansino4496
- Final ProjectUploaded byjocansino4496
- Project 06Uploaded byjocansino4496
- Project 03Uploaded byjocansino4496
- JavaScript Last Long Exam-Practical ExamUploaded byjocansino4496
- 17403_CS2finalreviewUploaded byjocansino4496
- JavascriptUploaded byjocansino4496

- Culler - 'Philosophy and Literature; The Fortunes of the Performative'Uploaded byKam Ho M. Wong
- Tagesspiegel Supplement 2011Uploaded byekmixon
- 325 - Disomangcop v. Secretary of DPWHUploaded byjrvyee
- Philosophy Notes30Uploaded byPradeep Thawani
- essayUploaded byapi-308039273
- Applied Combinatorics 5th Edition by Tucker Instructor's ManualUploaded byZahaib Akhtar
- Theory & Practice GogueUploaded byJoannaLin
- 2008_MD Tang Chen Sutarso Bad Apples Bad BusinessUploaded bytosutea
- Flyvbjerg B. 1998. Rationality and Power_Democracy in Practice.pdfUploaded byJorge Daniel
- outsidersworksheetsforweeblyUploaded byapi-207259783
- 120118_durhamUploaded byGeorge Vlad
- IEEE_05391Fast Sequential Decoding Algorithm Using a Stack711Uploaded bymahnaznamazi
- LAW -JurisprudenceUploaded byArunaML
- LatinUploaded byelazaroc
- 9781461452744-c1Uploaded bylaukune
- studyandthinkingskillsinenglish-091020094244-phpapp01.pptUploaded byFrancisEmmanuelGonzaga
- oncoaliados site summary 13-14Uploaded byapi-238723311
- 106 TOP Control Systems - Electrical Engineering Multiple Choice Questions and Answers _ MCQs Preparation for Engineering Competitive ExamsUploaded byAli Raza
- Projectivna geometrijaUploaded byRaleGarfild
- Urban SpaceUploaded bySana Meraj
- Basic Schools of ManagementUploaded byM G
- Paradox in Wave-Particle Duality*Uploaded byjuannaviap
- Varieties of EthnographiesUploaded byEmerich Dar
- phet the moving man simulationUploaded byapi-341972466
- Kushi - Macrobiotic Dietary recommendationsUploaded bytilopa
- Article 11Uploaded byoktikiki
- Anapana PabbaUploaded byParamartha Dhamma
- Etika Penelitian Dr.meitaUploaded byFathin Rahmani Salman
- Gramatica Urbana en Las PerifieriasUploaded byYessenia Salazar
- Ethics in Corporate Financial ReportingUploaded byNeerunjun Hurloll