Chapter 2 Clarifications

Slides:



Advertisements
Similar presentations
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
Advertisements

Java Syntax. Basic Output public class test1 { public static void main(String[] args) { System.out.println("Hello"); }
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
LAB 10.
Computer Programming Lab(4).
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
1 BUILDING JAVA PROGRAMS CHAPTER 3 THE SCANNER CLASS AND USER INPUT.
Computer Programming Lab(5).
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Lecture 2: Classes and Objects, using Scanner and String.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
1 Variables. 2 Receipt example What's bad about the following code? public class Receipt { public static void main(String[] args) { // Calculate total.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Review :chapters What is an algorithm? A step by step description of how to accomplish a task. For example, Adding 3 numbers N1, N2 and N3 Add.
Java Review if Online Time For loop Quiz on Thursday.
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
Computer Programming1 Computer Science 1 Computer Programming.
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.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Intro to Programming STARS College of Communication and Information Florida State University Written by: Hannah Brock Alissa Ovalle Nicolaus Lopez Martin.
L AB #3. System.out.println(“if you have” +eggPerBasket + “egg per basket and” + numberOfBaskets +”baskets, then the total number off eggs is“+totalEggs);
Day Programming with Methods. The “do” loop The “do” loop is a type of while loop that only does one iteration (does one loop at least) It is hardly.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Department of Computer Science
Chapter 2 Elementary Programming
Repetition.
Data types, Expressions and assignment, Input from User
TK1114 Computer Programming
SELECTION STATEMENTS (1)
Something about Java Introduction to Problem Solving and Programming 1.
BIT115: Introduction to Programming
Control Statement Examples
Starting Out with Java: From Control Structures through Objects
Decision statements. - They can use logic to arrive at desired results
Java Fix a program that has if Online time for Monday’s Program
Stack Memory 2 (also called Call Stack)
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Classes and Methods
Java so far Week 7.
AP Java Review If else.
Java Fix a program that has if Online time for Monday’s Program
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
AP Java Review If else.
CSC1401 Input and Output (with Files)
Random Numbers while loop
Consider the following code:
More on iterations using
Optional Topic: User Input with Scanner
Presentation transcript:

Chapter 2 Clarifications How to see the results of a statement What is a Logical Flow?

What is the result of a statement? How do you see what the result is? When you have the following code, how do you know what the result was? public class TestMath { public static void main(String[] args) { Math.pow(10, 4); }// end main }// end class

Why use System. out. println(); Why use System.out.println(); ? It lets you see the result to the screen Using System.out.println(); in the code, lets you see the result of the statement. public class TestMath { public static void main(String[] args) { System.out.println(Math.pow(10, 4)); }// end main }// end class

To store the result of the statement Assigning a variable the result of a statement lets you store that in memory to be used later. public class TestMath { public static void main(String[] args) { double result = Math.pow(10, 4); System.out.println(result); }// end main }// end class

When can I perform a calculation on variables? Can the following calculation be performed? public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); int y = x * x; int x = input.nextInt(); }// end main } //end class

Does the user know he or she needs to enter data? import java.io.*; import java.util.*; public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); int x = input.nextInt(); int y = x * x; }// end main } //end class

How informative is this to the user? public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a number:"); int x = input.nextInt(); int y = x * x; System.out.println(y); }// end main } //end class

Useful information is now provided to the user public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a number:"); int x = input.nextInt(); System.out.println("Your number is " + x); int y = x * x; System.out.println(y + " is " + x + " squared."); }// end main } //end class