Monday, January 28, 2008

HAHAHA. In lab now. spent like 10 minutes doing the println exercise, another 10 mins to do the declare two integers and their sum thing.. then spent ard 50 mins or so wondering how to write the script for numbers to be keyed in instead of being stated. just realised not long ago that import java.io.*; is part of the script. LOL.
yay. my script :P
import java.io.*;
class Testingoutsomething {
public static void main(String[] args) throws IOException {
int num1; int num2;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter num1 : ");
String string_1 = input.readLine();
int a = Integer.parseInt (string_1);
//start of a new line!
System.out.print("Enter num2 : ");
String string_2 = input.readLine();
int b = Integer.parseInt (string_2);
//A third integer!
System.out.print("Enter num3: ");
String string_3 = input.readLine();
int c = Integer.parseInt (string_3);
int sum = a+b+c;
System.out.println("The sum of " + a + " and " + b + " and " + c + " is " + sum + "!");
}
}

No comments: