Monday, March 13, 2006

Lab Scanner (lab 4)

程式碼:
package s9226307;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class s9226307 {
public s9226307() {
}

public static void main(String[] args) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
System.out.println("Enter number og pods");
String podString = keyboard.readLine();
int numberOfPods = Integer.parseInt(podString);
System.out.println("Enter number of peas in a pod:");
String peaString = keyboard.readLine();
int peasPerPod = Integer.parseInt(peaString);

int totalNumberOfPeas = numberOfPods*peasPerPod;
System.out.println(numberOfPods + " pods and ");
System.out.println(peasPerPod + " Peas per pod. ");
System.out.println("The total nimber of peas " + totalNumberOfPeas);
}
}

0 Comments:

Post a Comment

<< Home