8 views

Uploaded by janellequianzon

sem2 homework

save

- Section17 Greatest Common Factors and Least Common Multiples
- 0708-06
- About StringBuffer and String (SCJP Forum at JavaRanch)
- Algorithm Analysis Design Lecture1 PowerPoint Presentation
- Assessment and Design of GetTemp and SetDisp Subroutines
- BSP-2018-HW3-Solutions.pdf
- R1-00-0486
- Net June 2013
- 27701472 Introduction to Flex
- Cloudera_Academic_Partnership_3.pdf
- Tuxedo Helper
- split-up-IP-XI-2015
- Experiment Lecture
- Quantum Computers
- 10 Numth Annotated
- Java Printf Method Quick Reference
- recursion
- Mainframes Refresher
- Create Server Audit (Transact-SQL)
- easyctf_writeups
- Java mock tests for SCJP
- Exp 4
- th
- Mainframes Refresher
- Reference.card Ksh.programming
- Visual Basic Labmanual
- 2E Worksheet 2 (Simultaneous Eqns - Eliminatn Method)
- paper-3
- POD_Code_Chen_et_al
- J602 RefCard Color Letter Current
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- Dispatches from Pluto: Lost and Found in the Mississippi Delta
- Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
- The Unwinding: An Inner History of the New America
- Yes Please
- Sapiens: A Brief History of Humankind
- The Prize: The Epic Quest for Oil, Money & Power
- The Emperor of All Maladies: A Biography of Cancer
- A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
- Grand Pursuit: The Story of Economic Genius
- This Changes Everything: Capitalism vs. The Climate
- Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
- John Adams
- Smart People Should Build Things: How to Restore Our Culture of Achievement, Build a Path for Entrepreneurs, and Create New Jobs in America
- The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
- Rise of ISIS: A Threat We Can't Ignore
- The World Is Flat 3.0: A Brief History of the Twenty-first Century
- The New Confessions of an Economic Hit Man
- Team of Rivals: The Political Genius of Abraham Lincoln
- Bad Feminist: Essays
- Angela's Ashes: A Memoir
- Steve Jobs
- How To Win Friends and Influence People
- The Incarnations: A Novel
- You Too Can Have a Body Like Mine: A Novel
- The Sympathizer: A Novel (Pulitzer Prize for Fiction)
- Extremely Loud and Incredibly Close: A Novel
- Leaving Berlin: A Novel
- The Silver Linings Playbook: A Novel
- The Light Between Oceans: A Novel
- Brooklyn: A Novel
- The Flamethrowers: A Novel
- The First Bad Man: A Novel
- We Are Not Ourselves: A Novel
- The Blazing World: A Novel
- The Rosie Project: A Novel
- Bel Canto
- The Master
- A Man Called Ove: A Novel
- The Love Affairs of Nathaniel P.: A Novel
- Life of Pi
- The Cider House Rules
- A Prayer for Owen Meany: A Novel
- My Sister's Keeper: A Novel
- The Perks of Being a Wallflower
- Lovers at the Chameleon Club, Paris 1932: A Novel
- The Bonfire of the Vanities: A Novel
- Beautiful Ruins: A Novel
- The Kitchen House: A Novel
- Interpreter of Maladies
- The Wallcreeper
- The Art of Racing in the Rain: A Novel
- Wolf Hall: A Novel

You are on page 1of 5

Prepare and test a method entitled square that returns the square of its single parameter. def square(int sq) { sq * sq } n1 = 9 n2 = 5 println 'The square root of ' +n1+ ' is: ' +square(n1) println 'The square root of ' +n2+ ' is: ' +square(n2) RESULT:

3. Write and test a method to determine whether a given time of day is before another. Each time is represented by a triple of the form 11, 59, AM, or 1, 15, PM. def compareDate(h1,m1,d1,h2,m2,d2) { if (d1=="AM" && d2=="PM") return true else if(d1 == 'AM' && d2 == 'AM' || d1 == 'PM' && d2 == 'PM') { if(h1==h2) { if(m1<m2) return true else return false

h2.m2.d1.m1.d2)) println h1+ ':' +m1 + d1+ ' is before ' +h2+ ':' +m2 + d2 else println h1+ ':' +m1 + d1+ ' is not before ' +h2+ ':' + m2 + d2 RESULT: .} else if(h1<h2) return true else return false } else return false } def h1 = 10 def m1 = 23 def d1 = "AM" def h2 = 11 def m2 = 23 def d2 = "AM" if(compareDate(h1.

def isEven(num) { if (num%2==0) return true else return false } def isPowerOfTwo(num) { if (num == 0) return true else if (num==1 && isEven(num)) isPowerOfTwo(num/2) else return false } def num = 20 if (isEven(num)) println num+ " is even" else . develop a recursive method isPowerOfTwo that determines if its single parameter is a power of 2. . 2. using isEven. are powers of the value 2..def h1 = 10 def m1 = 23 def d1 = "PM" def h2 = 11 def m2 = 23 def d2 = "AM" 4. First. The values 1. Then. 8. develop a method isEven that determines whether its single integer parameter is an even value. 4.. 16.

... that is.. reads the same forward and backward: def isPalindrome(str) { . } Using these two methods.. which accepts a list of Strings and concatenates them into a single String: def implode(strList) { .println num+ " is not even" if (isPowerOfTwo(num)) println num+ " is a power of two" else println num+ " is not a power of two" RESULT: Def num = 8 13. Develop a method entitled explode that transforms a string into a List of Strings of size one. } Now.. The method signature is: def explode(str) { . develop the method reverseString for reversing the characters of a String parameter: def reverseString(str) { . develop the method isPalindrome to return the boolean true if the single String parameter is palindromic. develop the complementary method implode.. } . } Finally.

m) otherwise Implement a method to realize this and show that gcd(18. m) = gcd(n.n) else return gcd(m.m) { if (m<n && n%m==0) return m else if (n<m) return gcd(m.15.m) RESULT: . It is defined recursively as: gcd(n. m) = gcd(n – m. The greatest common divisor of two integers can be determined from Euclid’s algorithm. m – n) if n < m gcd(n. 27) is 9.n%m) } def n = 18 def m = 27 println 'GCD of ' +n+ ' and ' +m+ ' is ' +gcd(n. def gcd(n. m) = n if n == m gcd(n.

- Section17 Greatest Common Factors and Least Common MultiplesUploaded bymarchelo_chelo
- 0708-06Uploaded byU U UjjwalSquare
- About StringBuffer and String (SCJP Forum at JavaRanch)Uploaded bykenni18
- Algorithm Analysis Design Lecture1 PowerPoint PresentationUploaded byPedro Ped
- Assessment and Design of GetTemp and SetDisp SubroutinesUploaded bymaqib724
- BSP-2018-HW3-Solutions.pdfUploaded byChandreshSingh
- R1-00-0486Uploaded byTaki Eddine
- Net June 2013Uploaded bySunil Pandey
- 27701472 Introduction to FlexUploaded bysmilevinoth
- Cloudera_Academic_Partnership_3.pdfUploaded byyo2k9
- Tuxedo HelperUploaded bysocknow
- split-up-IP-XI-2015Uploaded byvikas_2
- Experiment LectureUploaded byCasandra Victorio Kua RN
- Quantum ComputersUploaded byMaitry Mehta
- 10 Numth AnnotatedUploaded byDhruv Kohli
- Java Printf Method Quick ReferenceUploaded byPhiokham Suriya
- recursionUploaded bytheresa.painter
- Mainframes RefresherUploaded byRajesh Pabbishetty
- Create Server Audit (Transact-SQL)Uploaded bydaking
- easyctf_writeupsUploaded bySaishDabholkar
- Java mock tests for SCJPUploaded byThyagarajan
- Exp 4Uploaded byNivi Senthil
- thUploaded byjamesyu
- Mainframes RefresherUploaded byMystic Guy
- Reference.card Ksh.programmingUploaded byNalin Vilochan
- Visual Basic LabmanualUploaded byAjeet Kumar Singh
- 2E Worksheet 2 (Simultaneous Eqns - Eliminatn Method)Uploaded bynateidde
- paper-3Uploaded byRama Krishna
- POD_Code_Chen_et_alUploaded byManeesh Mishra
- J602 RefCard Color Letter CurrentUploaded bycijumatsu