星期一, 10月 17, 2005

Lab Scanner

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class ScannerDemo
{
public static void main(String[] args) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
System.out.println("Enter the number of pods followed by");
System.out.println("the number of peas in a pod:");
int numberOfPods=Integer.parseInt(keyboard.readLine());
int peasPerPod=Integer.parseInt(keyboard.readLine());
int totalNumberOfPeas=numberOfPods*peasPerPod;
System.out.print(numberOfPods+" pods and ");
System.out.println(peasPerPod+" peas per pod.");
System.out.println("The total number of peas ="+totalNumberOfPeas);
}
}

0 Comments:

張貼留言

<< Home