ScannerTest - Scanner parser = new Scanner(text);

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab04; p import java.util.Scanner; i import lab02.Atom; i public class ScannerTest { p public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter a Name"); String NAME = input.nextLine(); System.out.println("Enter the number of kids"); int NUMBER_OF_KIDS = input.nextInt(); System.out.println("Enter true or false"); String TRUE_OR_FALSE = input.next(); System.out.println("Enter your name"); String MY_NAME = input.next(); System.out.println("Dear " + NAME); System.out.print("Wow, what a year. I hope your " + NUMBER_OF_KIDS); System.out.println(" kids are well. The rumors that we are expecting another are " + TRUE_OR_FALSE); System.out.println("Sincerely, "); System.out.println(MY_NAME); String text = "1 one ichi uno un eins";
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Scanner parser = new Scanner(text); System.out.println("Number: " + parser.nextInt()); System.out.println("English: " + parser.next()); System.out.println("Japanese: " + parser.next()); System.out.println("Spanish: " + parser.next()); System.out.println("French: " + parser.next()); System.out.println("German: " + parser.next()); Scanner parser = new Scanner("Uranium,U,92,92,146"); parser.useDelimiter(","); // Skip over first two fields. Notice how we can just ignore the value // returned by the next() method? parser.next(); parser.next(); int protonCount = parser.nextInt(); int electronCount = parser.nextInt(); int neutronCount = parser.nextInt(); Atom u238 = new Atom(protonCount, neutronCount, electronCount); } }...
View Full Document

This note was uploaded on 09/20/2011 for the course COM SCI 227 taught by Professor Staff during the Spring '11 term at Iowa State.

Ask a homework question - tutors are online