The keyboard is the standard input device.

Slides:



Advertisements
Similar presentations
Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
Advertisements

The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
BUILDING JAVA PROGRAMS CHAPTER 6.4 FILE OUTPUT. 22 PrintStream : An object in the java.io package that lets you print output to a destination such as.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 3 Console Output Keyboard Input Numerical.
Chapter 2: Java Fundamentals Input and Output statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 3 Console Output Keyboard Input Numerical.
Input and Output The system console. In the beginning … When computers were relatively expensive and rare, most users interacted with a terminal –CRT.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMP 14: I/O and Boolean Expressions May 24, 2000 Nick Vallidis.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
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;
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Week 2 - Friday.  What did we talk about last time?  Using Scanner to get input  Basic math operations.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
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.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
String and Scanner CS 21a: Introduction to Computing I First Semester,
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Building java programs, chapter 3 Parameters, Methods and Objects.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
Chapter 3 Numerical Data. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
CSC 142 H 1 CSC 142 Standard input/output. CSC 142 H 2 Console Ouput  Use the static PrintStream object out in System System.out.println("Hello, world");
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
Midterm 2 Review. Stars and why we use nested loops  Matrix problems (stars)  Other problems involving multiple dimensions  Loops within a process.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
Keyboard and Screen I/O (Input/Output). Screen Output  System.out is an object that is part of the Java language. (Don’t worry yet about why there is.
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
Simple Console Output CS 21a. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
Input and Output The system console. In the beginning … When computers were relatively expensive and rare, most users interacted with a terminal –CRT.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Java Fundamentals 4. Java Programming: From Problem Analysis to Program Design, Second Edition2 Parsing Numeric Strings  Integer, Float, and Double are.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Lecture 4 – Scanner & Style
User Input ICS2O.
Java Fundamentals 4.
Chapter 2 Basic Computation
Input/Output.
Chapter 2 More on Math More on Input
CPS120: Introduction to Computer Science
Introduction to C CSE 2031 Fall /3/ :33 AM.
Variables, Expressions, and IO
Chapter 5: Control Structures II
Chapter 2 Basic Computation
OUTPUT STATEMENTS GC 201.
System.out.println for console output
IDENTIFIERS CSC 111.
Fundamentals 2.
Introduction to Computing Using Java
Chapter 2: Java Fundamentals
Introduction to Java Brief history of Java Sample Java Program
Introduction to Java Applications
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Unit 3: Variables in Java
Building Java Programs
CS 1054 Introduction to Programming in Java
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Chapter 2: Beginning to Program
Presentation transcript:

The keyboard is the standard input device. Console I/O Console I/O is input from the standard input device and or output to the standard output device. The keyboard is the standard input device. The screen/monitor is the standard output device. Java gives us the Scanner class to to read from the keyboard (and text files). Java gives us System.out.print(), System.out.println() and System.out.format() to write text to the standard output device. 2

Console output using System.out.print() and println() System.out.println("Hello World"); // prints Hello World and a newline System.out.print("Hello World"); // prints Hello World without a newline int x=10, int y=5; System.out.println( "x+y=" + x + y ); // prints x+y=105 DO YOU SEE WHY? ( "x+y=10" + y ); // "x+y=" + 10 evals to "x+y=10" ( "x+y=105" ); // "x+y=10" + 5 evals to "x+y=105" The expression in the ()s must evaluate to a single value. That value will be printed as a string to the output. If there are numbers and Strings mixed around the + operator, the + operator will convert the number to a String and concatenate. The operators are evaluated * and / first (left to right) then + and – (left to right). System.out.println( "x+y=" + (x + y) ); // prints x+y=15 The ()s around the second x+y force it to evaluate before the first +. Nested ()s evaluate inside out.

System.out.format() When printing numbers to the screen you can control the format width and number of decimal places of precision using the format method. double pi = 3.14159265358979323846264338; // to 26 places // BUT only up to 15 places max can be stored System.out.println( "pi=" + pi ); // prints 3.14159265358979323846264338 // use format() to force max width of 6 places counting dot / with 4 coming after the dot. The 59 rounds to 6 System.out.format( "pi=%6.4f", pi ); // prints 3.1416

Input from keyboard using Scanner