CSE
Week5Ch4Intro

# Week5Ch4Intro - Chapter 4 Conditions and Loops Janaka...

• Notes
• 18

This preview shows pages 1–5. Sign up to view the full content.

Janaka Balasooriya CSE 110, Arizona State University Chapter 4 Conditions and Loops

This preview has intentionally blurred sections. Sign up to view the full version.

Quick Recap – Chapters 1, 2, and 3 Problem solving process and algorithm development Basic elements in C++ Data types • Arithmetic operations • Data variables and memory allocation • Compound statements ( +=, -= …) Operator precedence rules • Objects More about input/output • Standard input/output Formatting
Janaka Balasooriya CSE 110, Arizona State University Program Execution Dice Program (Partial) Structure of the program – Flow Chart Statement 1 Statement n Statement 2 - - - import java.util.Random; import java.util.Scanner; public class Dice { public static void main (String[] args) { Random ranGenerator = new Random(); Scanner keyboard = new Scanner(System.in); int dieOneSides, dieTwoSides, dieOne, dieTwo,sumOne=0, sumTwo=0; System.out.println("How many sides does die 1 have?"); dieOneSides=keyboard.nextInt(); System.out.println("How many sides does die 2 have?"); dieTwoSides=keyboard.nextInt(); dieOne = ranGenerator.nextInt(dieOneSides) + 1; System.out.println("Die 1 first roll = " + dieOne); sumOne += dieOne; dieTwo = ranGenerator.nextInt(dieTwoSides) + 1; System.out.println("Die 2 first roll = " + dieTwo); sumTwo += dieTwo; ……………………………………… dieTwo = ranGenerator.nextInt(dieTwoSides) + 1; System.out.println("Die 2 third roll = " + dieTwo); sumTwo += dieTwo; System.out.println("Die 1 rolled a total of " + sumOne + " and rolled " + sumOne/3.0 + "on average"); System.out.println("Die 2 rolled a total of " + sumTwo + " and rolled " + sumTwo/3 .0+ "on average"); } }

This preview has intentionally blurred sections. Sign up to view the full version.

Janaka Balasooriya CSE 100, Arizona State University Need to make decisions during the execution of the program Problem to be solved (Sum): Develop a program that read integers from the keyboard. Then, add
This is the end of the preview. Sign up to access the rest of the document.
• Fall '08
• Kim
• Equals sign, relational operator, Janaka Balasooriya

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern