A+ Computer Science -

Similar documents
A+ Computer Science -

Reading Input from Text File

Input. Scanner keyboard = new Scanner(System.in); String name;

Experiment No: Group B_4

ing execution. That way, new results can be computed each time the Class The Scanner

Computational Expression

Basic Computation. Chapter 2

Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal

Data Conversion & Scanner Class

Lecture 8 " INPUT " Instructor: Craig Duckett

A token is a sequence of characters not including any whitespace.

Fundamentals of Programming Data Types & Methods

BASIC INPUT/OUTPUT. Fundamentals of Computer Science

A+ Computer Science -

Robots. Byron Weber Becker. chapter 6

Lesson 3: Accepting User Input and Using Different Methods for Output

Computational Expression

Chapter 4: Conditionals and Recursion

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

Data Types and the while Statement

Programming with Java

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Chapter 2 ELEMENTARY PROGRAMMING

Basic Computation. Chapter 2

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

CSS 161 Fundamentals of Compu3ng. Assignments, Expressions, Operators, Console input & output October 1, 2012

Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6

Project 1. Java Data types and input/output 1/17/2014. Primitive data types (2) Primitive data types in Java

What two elements are usually present for calculating a total of a series of numbers?

Using Classes. GEEN163 Introduction to Computer Programming

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Console Input and Output

String s = "apluscs";

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Chapter 5 Lab Methods

Full file at

Intro to Programming in Java Practice Midterm

Chapter 5 Lab Methods

Computational Expression

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

Full file at

Basic Computation. Chapter 2

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Object Oriented Programming. Java-Lecture 1

COMP String and Console I/O. Yi Hong May 18, 2015

We now start exploring some key elements of the Java programming language and ways of performing I/O

AP Computer Science Unit 1. Programs

! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like

Loops. GEEN163 Introduction to Computer Programming

Introduction to Java Unit 1. Using BlueJ to Write Programs

STUDENT LESSON A7 Simple I/O

Computer Science 210 Data Structures Siena College Fall Topic Notes: Methods

Chapter 2. Elementary Programming

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

ECE 122 Engineering Problem Solving with Java

Programming II (CS300)

MIDTERM REVIEW. midterminformation.htm

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

AP Computer Science Unit 1. Writing Programs Using BlueJ

Using Java Classes Fall 2018 Margaret Reid-Miller

Topic 11 Scanner object, conditional execution

1 Short Answer (5 Points Each)

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

Chapter 2: Basic Elements of Java

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Chapter 2 Elementary Programming

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CSC 1214: Object-Oriented Programming

Supplementary Test 1

Chapter 5 Lab Methods

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

1 Short Answer (10 Points Each)

Over and Over Again GEEN163

AP Computer Science Unit 1. Writing Programs Using BlueJ

Chapter 4: Loops and Files

Lesson 7 Part 2 Flags

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Chapter 4: Loops and Files

Example Program. public class ComputeArea {

CS 106 Introduction to Computer Science I

CSIS 10A Assignment 4 SOLUTIONS

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Computer Science 145 Midterm 1 Fall 2016

Classes and Objects Part 1

Chapter 2 Primitive Data Types and Operations

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Important Java terminology

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

Elementary Programming

CSIS 10A Assignment 3 Due: 2/21 at midnight

A variable is a name for a location in memory A variable must be declared

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Primitive Data Types: Intro

Elementary Programming. CSE 114, Computer Science 1 Stony Brook University

Objectives. Primitive Types, Strings, and Console I/O. Variables and Values. Outline. Naming and Declaring Variables. Variables and Values

Transcription:

import java.util.scanner; or just import java.util.*;

reference variable Scanner keyboard = new Scanner(System.in); object instantiation

Scanner frequently used methods Name nextint() nextdouble() nextfloat() nextlong() nextbyte() nextshort() next() nextline() Use returns the next int value returns the next double value returns the next float value returns the next long value returns the next byte value returns the next short value returns the next one word String returns the next multi word String import java.util.scanner;

Scanner keyboard = new Scanner(System.in); System. out.print("enter an integer :: "); int num = keyboard.nextint();

System.out.print("Enter an integer :: "); int num = keyboard.nextint(); System. out.println(num); INPUT 931 OUTPUT Enter an integer :: 931 931

reference variable int num = keyboard.nextint(); method call

System. out.print("enter an integer :: "); Prompts are used to tell the user what you want.

Scanner keyboard = new Scanner(System.in); System.out.print("Enter a double :: "); double num = keyboard.nextdouble();

System.out.print("Enter a double :: "); double num = keyboard.nextdouble(); System.out.println(num); INPUT 34.33 OUTPUT Enter a double :: 34.33 34.33

reference variable double num = keyboard.nextdouble(); method call

Scanner keyboard = new Scanner(System.in); System.out.print("Enter a string :: "); String word = keyboard.next();

System.out.print("Enter a string :: "); String word = keyboard.next(); System.out.println(word); INPUT I love java. OUTPUT Enter a string :: I love java. I

Scanner keyboard = new Scanner(System.in); System.out.print("Enter a sentence :: "); String sentence = keyboard.nextline();

System.out.print("Enter a line :: "); String line = keyboard.nextline(); System.out.println(line); INPUT I love java. OUTPUT Enter a line :: I love java. I love java.

System.out.print("Enter an integer :: "); int num = keyboard.nextint(); System.out.print("Enter a sentence :: "); String sentence = keyboard.nextline(); System.out.println(num + " "+sentence); OUTPUT Enter an integer :: 34 Enter a sentence :: 34 INPUT 34 picks up \n nextline() picks up whitespace.

System.out.print("Enter an integer :: "); int num = keyboard.nextint(); keyboard.nextline(); System.out.print("Enter a sentence :: "); String sentence = keyboard.nextline(); out.println(num + " "+sentence); OUTPUT Enter an integer :: 34 Enter a sentence :: picks up \n 34 picks up \n //pick up whitespace INPUT 34 picks up \n nextline() picks up whitespace.

Scanner keyboard = new Scanner(System.in); System.out.println(keyboard.nextInt()); System.out.println(keyboard.nextInt()); System.out.println(keyboard.nextInt()); INPUT 1 2 3 4 5 OUTPUT 1 2 3

BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) ); System.out.print("Enter a word :: "); String s = keyboard.readline(); System.out.println(s + '\n' );

readline() reads in all data as text / string data. The text you read in must be converted over to the appropriate type before it can be stored. System.out.print("Enter an integer :: "); one = Integer.parseInt(keyboard.readLine()); System.out.print("Enter a double :: "); two = Double.parseDouble(keyboard.readLine());

//GUI INPUT BOX input= JOptionPane.showInputDialog("Enter an integer :: "); one = Integer.parseInt(input); //GUI OUTPUT BOX JOptionPane.showMessageDialog(null, "Integer value :: " + one);