星期一, 10月 17, 2005

Lab Scanner

Do Display 2.6 on Page 79.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

Change

Scanner keyboard= new Scanner(System.in);

into

BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));

String inputString = keyboard.readLine();

answer

import javax.swing.JOptionPane;

public class Untitled1 {
public Untitled1() {
}


public static void main(String[] args) {

String myString=JOptionPane.showInputDialog("Enter a number: ");
int myNumber=Integer.parseInt(myString);
System.out.println("The number is "+myNumber);
System.exit(0);
}
}

Lab JOptionPane

Use the following command to generate a window input dialog

String myString=JOptionPane.showInputDialog("Enter a number: ");

use the following command to convert a string to a number

int myNumber = Integer.parseInt(myString);

and finally use the following command to print the input number to the console

System.out.println("The number is "+ myNumber);

Don't forget the following import command

import javax.swing.JOptionPane;

so that Java can recognize JOptionPane library.

星期一, 10月 03, 2005

Lab 10-03-2005

Display 1.7 of Chap. 1

Project 5 of Chap. 1

"tell me and I'll forget; show me and I may remember; involve me and I'll understand"

星期一, 9月 26, 2005

Homework 3 09-26-2005

Reading Assignments
1. Chapter 1, Chapter 2

Homework
1. Project 1 on Page 55.

"nothing builds self-esteem and self-confidence like accomplishment"

Lab 2 09-26-2005

Do Project 4 on Page 56.

星期一, 9月 19, 2005

Homework 2

Homework Problems
1. Explain bytecode, JVM
2. Explain class, object
3. Let i=2;
Print i;
Print 2 * (i++);
Print i;

Ans: 2, 4, 3

4. Let i=2;
Print i;
Print 2 * (++i);
Print i;

Ans: 2, 6, 3

5. Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;

Ans: 3.5, 3.5

Reading Assignments
Read 1.1, 1.2, 1.3