09-22 Class Notes CS 107

09-22 Class Notes CS 107 - 09-22 Class Notes CS 107...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
- For midterm #1 in lab, you need to know how to write a program that manipulates characters on an input line. We'll do an example in class today. - /** * I/O > Console I/O > ConsoleIOScanner.java * * Reads text from standard input using console I/O using the Scanner class. * This does not work in versions of Java previous to Java 5 (aka 1.5) * @author Dale Reed */ import java.util.Scanner; public class Midterm1Prep { public static void main(String[] args) { Scanner keyboard = new Scanner( System.in); System.out.print( "Enter some text: " ); String userInput = keyboard.nextLine(); // read a string // go through all the characters and print out any upper case // characters for( int i=0; i<userInput.length(); i++) { // copy the ith character char c = userInput.charAt( i); // print it if it is upper case System.out.print( c); } } }//end main() }//end class /* sample run: * Enter some text: Dorks are Only Women when Entirely Late to Lunch
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

09-22 Class Notes CS 107 - 09-22 Class Notes CS 107...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online