Download presentation
Presentation is loading. Please wait.
Published byTheodore Ryan Modified over 6 years ago
1
CSC1401 Input and Output (and we’ll do a bit more on class creation)
2
Learning Goals Computing concepts Input and output in Java
Using the Scanner class
3
To date We have been working with pictures, and with drawing, and with turtles We have not really been getting any input from the user Our output has mostly been limited to invoking show() or explore() on a picture
4
This next week We’ll be looking at textual programming –numbers and words (Strings), before going back to more graphical material after Thanksgiving Needed in lots of computational areas
5
Output in Java System.out.print() System.out.println()
Place what we want printed inside the () Use + to concatenate things System.out is an object (the standard output – the display on our computers)
6
Input in Java System.in is the standard input (the keyboard)
However, we need a special class, located in java.util.Scanner
7
Syntactically … import java.util.*; // needed for scanner
class IOTesting { public static void main(String [] args) { Scanner scan = new Scanner(System.in); int value = scan.nextInt(); …
8
Input What else can you read in besides ints? See the Javadoc
nextBoolean() nextDouble() nextFloat() nextLine() reads in a String etc.
9
Problem solving with Input and Output
Keeping track of exam grades for CSC1401 Then writing methods for: Finding out the exam average Printing out the grades Calculating the standard deviation (if I remember how to do it) Who got the highest grade? And what it was… etc.
10
ExamGrades class What variables do we need? What methods?
Building the class
11
Summary We use System.out for output to the terminal
We use System.in in conjunction with a Scanner object for getting input from the keyboard
12
Reading Assignment none
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.