Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

8 March 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Review Generics and the ArrayList Class
For(int i = 1; i
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Programming Methodology (1). Implementing Methods main.
Chapter 3A Review boolean fun = true; if(fun) System.out.print(“yeah!”);
What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
Computer Programming Lab(7).
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Multi-Dispatch in the Java Virtual Machine TM What is (dynamic) multi-dispatch? Method selection based on the types of … all (or more than one) of the.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt WHILE.
Q1 Review. Other News US News top CS Universities global-universities/computer- science?int=994b08.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Technology of Test Case Generation Levi Lúcio University of Geneva Marko Samer Vienna University of Technology.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Discussion1 Quiz. Q1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) e) DEFAULT_VALUE f) bad-choice.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
Lecture 12: Midterm Review Multiple choice quiz from pub website (see web page for link and use access code liang6e614 ) Homework 5: N Queens Sample midterm.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
1 Gentle Introduction to Programming Tirgul 2: Scala “hands on” in the lab.
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
Hudson Valley Community College CISS-110 – Programming & Logic I David Goldschmidt, Ph.D.
LOOPING What are the 3 structures of writing code? sequential decision repetition Def. Looping is the repetition of statements in a program. There various.
Formatting Screen Output How do I make my numbers look pretty?
Practice with Lists and Strings CS303E: Elements of Computers and Programming.
1 Variables. 2 Receipt example What's bad about the following code? public class Receipt { public static void main(String[] args) { // Calculate total.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
The PC GadgetMaster II Stepper Motor Control Developed by Frank Shapleigh Edited by Jim Tuff.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
A: A: double “4” A: “34” 4.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
C Programming Chapters 11, . . .
Method Examples CS 139 Algorithm Development 10/06/2008.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Lesson 07: Strings Class Chat: Attendance: Participation
Java for Beginners Level 6 University Greenwich Computing At School
Formatting Screen Output How do I make my numbers look pretty?
Lesson 07: Strings Topic: Introduction to Programming, Zybook Ch 6, P4E Ch 6. Slides on website.
Register Use Policy Conventions
Arrays & pointers C How to Program, 8/e.
CSC 113: Computer programming II
Arrays November 8, 2017.
Lists in Python Outputting lists.
Bracket Operator.
Observing how the machine acts
Class 2.
Assignment Operators Topics Increment and Decrement Operators
Java for Beginners University Greenwich Computing At School DASCO
105-1 Data Structure Homework 1
Assignment Operators Topics Increment and Decrement Operators
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Assignment Operators Topics Increment and Decrement Operators
Parameter: an input to a method
Lesson 07: Strings Class Chat: Attendance: Participation
Table 3. Decompression process using LZW
Assignment Operators Topics Increment and Decrement Operators
Mcafee.Com/Activate | Activate And Renew Your Mcafee Antivirus Subscription
Challenge Guide Grade Code Type Slides
Presentation transcript:

Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number != 0);

Write code snippet to replace every 'a' in the String S8 with 'x' Note – we can’t replace an element in a String. So – how in the world can we do this?

Hand Trace and Output: int total = 25; for (int number = 1; number <=(total / 2); number++) { total = total + number; System.out.println(total + " " + number); }

Hand Trace and Output: for (int i = 1; i <=3; i++) System. out Hand Trace and Output: for (int i = 1; i <=3; i++) System.out.println("How many lines"); System.out.println("are printed?");

Hand Trace and Output: Hint In your hand trace, include 10 - i and 2 Hand Trace and Output: Hint In your hand trace, include 10 - i and 2*i -1 as columns for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10 - i ; j++) System.out.print(" "); } for (int j = 1; j <= 2* i -1; j++) System.out.print("*"); System.out.println();

5. Hand Trace and Output int n1 = 1; while (n1 < 100) { System. out 5. Hand Trace and Output int n1 = 1; while (n1 < 100) { System.out.print(n1 + " "); n1 += 10; }

6. Hand Trace and Output int n1 = 100; while (n1 > 0) { System. out 6. Hand Trace and Output int n1 = 100; while (n1 > 0) { System.out.println(n1 / 10); n1 = n1 / 2; }

7. Given: // Pre: int // Post: nothing public static void mystery(int x) { int y = 1; int z = 0; while (2 * y <= x) y = y * 2; z++; } System.out.println(y + " " + z); What is Output: mystery(1) mystery(19)

8. Write method called randomX in systemMethods that prints a line that contains a random number of "x" characters (between 5 and 20 inclusive) until it prints a line that contains 16 or more characters. For example, the output might look like xxxxxxxx xxxxxxxxxxx xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxx

9. Write a method checkLet that accepts a String and a char and returns true or false which is the answer to the question "Is the char in the String?".