Regular loops and For loops Notes
Regular loops and For loops Notes COSC 236
Popular in Introduction to COSC 1
Popular in ComputerScienence
This 0 page Class Notes was uploaded by Jessica Hutchinson on Thursday February 18, 2016. The Class Notes belongs to COSC 236 at Towson University taught by Robert G. Eyer in Spring 2016. Since its upload, it has received 28 views. For similar materials see Introduction to COSC 1 in ComputerScienence at Towson University.
Reviews for Regular loops and For loops Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/18/16
Chapter 3 loops 0 Using a method to capture redundancy of a process This helps to limit output Nest loops star box example This code shows how to do a nested loop to produce a square box with stars as its outline The outer loop tells the program how many lines and the inner loop tells the actual data 0 All methods must start with public static void Main method printStars13 printStars7 printStars25 printSBox93 printBox54 Public static void printStarshowMany For i1 ilt howMany i Systemoutprintnquotquot Systemoutprintn Public static void printBox int howHigh int howWide printStarshowWide for int l 1 l lt howHighZ l systemoutprintquotquot for intj 1 lt howWideZ J39 Systemoutprintquot quot Systemoutprintn Value semantics when variables in main are copied into a parameter c A string variable is an object Example of code that prints out the average of 4 numbers public class Average4 public static double average4doube numl double num2 double num3doube num4 double average num1num2num3num44 return average public static void mainString args Systemoutprintnaverage415 22112 Example of code that scans the data the user inputs and nd the minimum import javautiScanner public class Awesomeness public static void mainString args Scanner console new ScannerSystemin SystemoutprintquotEnter 5 integers prompt int numl consolenextlnt int num2 consolenextlnt int num3 consolenextlnt int num4 consolenextlnt int num5 consolenextlnt int lowest numl forint i0 iltowest i if i gt lowest owesti Systemoutprintnquotthe lowest number is quot lowest int sum num1num2num3num4num5 SystemoutprintnquotThe sum is quot sum Example of code that prints this drawing gtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtlltgtllt public class drawFigure public static void mainString args forint s5s gt0 S forint is22 i gt0 ii2 Systemoutprintquotquot for intj 5 js gt0 j Systemoutprintquotquot forint ks22 k gt0 kk2 Systemoutprintquotquot Systemoutprintn end for line end main Printing Exponents Loop
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'