Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 7: Loops 22 February JavaLab7 lecture slides.ppt Ping Brennan
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Looping while … do …. Condition Process 2 Process 1 Y Repeated Loop.
While Loops. Challenge: ● Ask the user a simple math questions ● Continue asking the question until the user gets it right.
Week 5 - Friday.  What did we talk about last time?  Repetition  while loops.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Java Programming Practice.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Loops Counting down from N to 1 in assembly we used JUMP statements to repeat previous instructions thus looping READ LOOP: WRITE SUB decrement JPOSLOOP.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 Gentle Introduction to Programming Session 2: Functions.
Functions That Do Not Return a Value 03/09/11. Reminders  Quiz 3 Friday Work with partner on for-loop activity. Work with partner on for-loop activity.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough September 28, 2007.
JavaScript with Input & Output Step 1: Use tags JavaScript Template.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Java Programming Practice.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Basics of Recursion l Programming with Recursion Recursion.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Intro to Java Day 3 / Loops 1. DAY 3 Java Language Specifications Conditional Loops while do for References: JavaNotes7 pdf bookJavaNotes7 pdf book.
Count and add list of numbers From user input and from file.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
HOMEWORK REVIEW. SOLVE ABSOLUTE VALUE INEQUALITIES 5.6.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Week 4 : Function with parameters and return values.
Chapter 7 Problem Solving with Loops
Computer Science: A Structured Programming Approach Using C1 6-6 Loop Examples This section contains several short examples of loop applications. Each.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.217, Problem 04.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Escape sequence Certain characters, preceded by a backslash ( \ ), are known as escape sequences They are used to display certain characters, or as display.
L AB 4 July 5th. F OR LOOP Exercise 1: Find two ways of “Summing all 1, 2, and 3 digit prime numbers.” Use for loop Hint: isprime, primes.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Nested Loops CS303E: Elements of Computers and Programming.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 1 Introduction to Java
THE AREA OF A CIRCLE An introduction to approximating the area of a circle.
Topics discussed in this section:
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Control Structure Senior Lecturer
Repetition and Loops while do while for continue break
More Loops.
Count Controlled Loops (Nested)
Intro to Nested Looping
Topics discussed in this section:
CSCE 206 Lab Structured Programming in C
INC 161 , CPE 100 Computer Programming
Console.WriteLine(“Good luck!”);
Class Examples.
Programming Assignment #1 12-Month Calendar—
Intro to Nested Looping
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Intro to Nested Looping
Print the following triangle, using nested loops
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
CSCE 206 Lab Structured Programming in C
Computer Science Club 1st November 2019.
Presentation transcript:

Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08

The problem Write a program that asks the user to enter the size of a triangle to print out (an integer from 1 to 50), then print the triangle by printing a series of lines consisting of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number enteed by the user. On the next line print one less asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only one asterisk is printed. Hint: Use nested for loops; the outside loop controls the number of lines to print, and the inside loop controls the number of asterisks to print on a line. For example, if the user enters 5, the output would be

* * * * * * * * * * * * * * * * *