New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

COSC 236 decision structures 2 lecture

by: Kelsey Voelker

COSC 236 decision structures 2 lecture COSC 236

Marketplace > Towson University > Computer science > COSC 236 > COSC 236 decision structures 2 lecture
Kelsey Voelker

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

lecture on decision structures (p2)
Intro to Computer Science 1
Dr. Alkharouf
Class Notes
25 ?




Popular in Intro to Computer Science 1

Popular in Computer science

This 3 page Class Notes was uploaded by Kelsey Voelker on Monday October 3, 2016. The Class Notes belongs to COSC 236 at Towson University taught by Dr. Alkharouf in Fall 2016. Since its upload, it has received 4 views. For similar materials see Intro to Computer Science 1 in Computer science at Towson University.


Reviews for COSC 236 decision structures 2 lecture


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: 10/03/16
Comp sci 236 9/26/16 lecture notes Decision Structures 2  Variable Scope o Where the variable exists (where it can be seen)  Locally, in main method, in between braces, etc. o In java, a local variable does not have to be declared at beginning of method o The Scope of a local variable = at the point it is declared and terminates at the end of the method o when program enters section of code where a variable has scope, that variable has come into scope the variable is visible to the program  The Switch statement o The if-else statement allows you to make true/false branches  (switch statement makes this easier/looks nicer) o The switch statement allows you to use an ordinal value to determine how a program will branch o The switch statement can evaluate and integer type or character type variable  Makes decisions based on the value o Takes the form:  Switch (SwitchExpression) { case CaseExpression: // place one or more statements here break; case CaseExpression: // case statements may be repeated //as many times as necessary default: // place one or more statements here }  Can put number or character in for switchexpression and then connect it to which case you want. they must match  Ex.--> switch (4) case 4; (will perform case 4)  The default is the “else” if they do not give you your casexpressions  Switch statement rules o Takes an ordinal value (byte, short, int, long, or char) o as SwitchExpression  switch (SwitchExpression)  {…} o evalutates the expression o if an associated case statement that matches that value, program execution will be transferred to that case statement  Case statement o Have a corresponding CaseExpression  Case CaseExpression: o If switchExpression matches CaseExpression, the Java statements between the colon and the break statement will be executed o The break statement ends the case statement o If a case does not contain a break, then program execution continues into the next case o The default section is optional and will be executed if no CaseExpression matches the SwitchExpression  The printf Method (for formatted printing) o Takes a format string, and an argument list o You can use the System.out.printf method to perform formatted console output o The general format of the method is:  System.out.printf(FormatString, ArgList);  FormatString a string that contains text and/or special formatting specifiers  ArgList is optional. It’s a list of additional arguments that will be formatted according to the format specifiers listed in the format string. o Ex.  Int hours = 40;  System.out.printf(“I worked %d hours.\n”, hours);  Output I worked 40 hours  %d format specifier, indicates that an integer will be printed  hours the contents of the hours variable will be printed in the location of the %d format specifier o Ex. 2  Int dogs = 2, cats = 4;  System.out.printf(“We have %d dogs and %d cats.\n”, dogs, cats);  Output We have 2 dogs and 4 cats o Ex. 3  Double grossPay = 874.12;  System.out.printf(“Your pay is %f.\n”, grossPay);  Output Your pay is 874.120000  %f format specifier indicates that a floating-point value will be printed  grossPay the contents of the grossPay variable will be printed in the location of the %f format specifier o Ex. 4  Double grossPay = 874.12;  System.out.printf(“Your pay is %.2f.\n”, grossPay);  Output your pay is 874.12  %.2f format specifier indicates that a floating-point value will be printed, rounded to two decimal places o %s.\n indicates that a string will be printed (letters) o %6d\n the integer will appear in a field that is 6 spaces wide (specifying a width)  9 o %6.2f indicates the number will appear in a field that is 6 spaces wide, AND will be rounded to 2 decimal places 9.77


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


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'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Jennifer McGill UCSF Med School

"Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over $500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.