A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!

Slides:



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

More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
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.
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Strings as objects Strings are objects. Each String is an instance of the class String They can be constructed thus: String s = new String("Hi mom!");
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
LAB 10.
Computer Programming Lab(4).
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Computer Programming Lab(5).
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
Sahar Mosleh California State University San MarcosPage 1 System.out.println for console output System.out is an object that is part of the Java language.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Mixing integer and floating point numbers in an arithmetic operation.
Introduction to Programming
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.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Ihsan Ayyub Qazi Introduction to Computer Programming Recitation 3 Ihsan Ayyub Qazi.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
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.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
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.
1 Simple Input Interactive Input - The Class Scanner n Command-Line Arguments.
© A+ Computer Science - import java.util.Scanner; Try to be as specific as possible when using an import.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
Introduction to programming in java
© A+ Computer Science - Scanner frequently used methods NameUse nextInt()returns the next int value nextDouble()returns the next.
Chapter 2 Clarifications
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.
TemperatureConversion
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Computer Programming Methodology Input and While Loop
Repetition.
TK1114 Computer Programming
Something about Java Introduction to Problem Solving and Programming 1.
INPUT STATEMENTS GC 201.
Program Style Console Input and Output
CSS 161 Fundamentals of Computing Introduction to Computers & Java
Introduction to Classes and Methods
A+ Computer Science INPUT.
Lecture Notes – Week 2 Lecture-2
Introduction to Java Brief history of Java Sample Java Program
A+ Computer Science INPUT.
Random Numbers while loop
Consider the following code:
Presentation transcript:

A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!

A.P. Computer Science import java.util.Scanner; The Scanner class provides a way to read and parse input. It is often used to read input from the keyboard. Key methods are next and hasNext. Parse - to separate (a sentence or word) into parts

A.P. Computer Science Scanner keyboard = new Scanner(System.in); reference variable object instantiation

A.P. Computer Science Anytime you want user input, you must clearly state to the user what you want. System.out.println("Enter an int number : "); System.out.println("Enter a real number : ");

A.P. Computer Science

Scanner frequently used methods NameUse nextInt()returns the next int value nextDouble()returns the next double value nextFloat()returns the next float value nextLong()returns the next long value nextByte()returns the next byte value nextShort()returns the next short value next()returns the next one word String nextLine()returns the next multi word String

A.P. Computer Science Scanner keyboard = new Scanner(System.in); System.out.print("Enter an integer :: "); int num = keyboard.nextInt(); Type in the appropriate import statement (see previous slides!) in the Interactions pane of Dr. Java and then type in the code above.

A.P. Computer Science //scanner int example import java.util.Scanner; public class ScannerInts { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter an short number( to 32767) :: "); int shorty = keyboard.nextInt(); System.out.println(shorty); System.out.print("Enter an int number (-2billion to 2billion):: "); int inty = keyboard.nextInt(); System.out.println(inty); } Type this program in Dr. Java and make sure you understand the output.

A.P. Computer Science Scanner keyboard = new Scanner(System.in); System.out.print("Enter a double :: "); double num = keyboard.nextDouble();

A.P. Computer Science //scanner real example import java.util.Scanner; public class ScannerReals { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a float :: "); float f = keyboard.nextFloat(); System.out.println(f); System.out.print("Enter a double number :: "); double d = keyboard.nextDouble(); System.out.println(d); } Type this program in Dr. Java and make sure you understand the output.

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

A.P. Computer Science Scanner keyboard = new Scanner(System.in); System.out.print("Enter a sentence :: "); String sentence = keyboard.nextLine();

A.P. Computer Science //scanner string example import java.util.Scanner; public class ScannerStrings { public static void main(String args[ ]) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a multi-word sentence :: "); String sentence = keyboard.nextLine(); System.out.println(sentence); System.out.print("Enter a one word string :: "); String s = keyboard.next(); System.out.println(s); } Type this program in Dr. Java and make sure you understand the output.

A.P. Computer Science Scanner keyboard = new Scanner(System.in); System.out.println(keyboard.nextInt()); OUTPUT INPUT

A.P. Computer Science //scanner string example import java.util.Scanner; public class ScannerStrings { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a multi-word sentence :: "); String sentence = keyboard.nextLine(); System.out.println(sentence); System.out.print("Enter a one word string :: "); String s = keyboard.next(); System.out.println(s); }