2009年6月23日 星期二

我有話要說

我在大一時對於c++並沒有學的很好,而大二時修資料結構更是修的十分痛苦,因為概念懂,但是程式碼就是背不起來,也看不懂(就算期中得了滿分還是死在期末考)。但是這學期修了java讓我這個程式苦手能夠稍微寫一些程式,或是看懂別人程式在做什麼,他的想法如何對我而言已經是十分大的進步了(有如阿公那輩的人學會用電腦那種感慨),而讓我覺得java最不一樣的地方在於他很直接,我缺什麼就補什麼,如a+bi我只要把相加的式子寫出來就完成一半了,我也可以偷懶不想一直打a+"+"+b+"i"而建構一個String去幫我偷懶。
除了看課本和聽老師講解之外,我室友也幫了我不少忙,像是之前要小考以及小考0分時,他很有耐性的教導我解決我的疑惑或是我不懂的地方,我認為,進部的相反並不是退步,而是什麼都不去做,我沒有因為不懂就放他去,也遇到願意幫我課後教學的人,我認為這是我除了學會java的初步課程之外最大的收穫。

2009年6月19日 星期五

http://sofree.cc/intro-wordpress-2-8/
http://cjhtech.blogspot.com/2007/02/blogger.html

2009年6月15日 星期一

Lab Hanoi Tower

The pseudocode for Hanoi Tower is as follows:

solve(N, Src, Aux, Dst)
if N is 0 return
solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
solve(N-1, Aux, Src, Dst)


Write the Java program based on the pseudocode in the above

.


Lab Recursive method

Write a recursive method to compute Fibonacci series.

Hint:

1.
fib(n)=fib(n-1)+fib(n-2)

2.
public static long fib(int n)




fib(1)


fib(5)


fib(10)


Lab Factorial

Write a Java program that computes N! where N is a positive integer.

Hint:

public static long factorial(int n)




0!的情形


1!的情形


10!的情形

2009年6月8日 星期一

Homework 6-1-2009 Modular Sorting

Write a sort method which takes a double array as parameter
and returns the sorted array. Call this method in a main program.

Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.



-----.





----
package javaapplication8;

/**
*
* @author KFN
*/
public class Sort
{

/** Creates a new instance of Sort */
public Sort()
{
}

public static void sort( double[] score ) {
int index = 0;
double temp = 0.0;
for( index = score.length-1; index >-1 ; --index)
{
for (int j = 0; j < index; j++)
{
if(score[index] > score[j])
{
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}


}

}

---
package javaapplication8;

/**
*
* @author KFN
*
*/
import java.util.Scanner;
public class ArrayOfScores
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;

System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index < score.length; ++index)
score[index] = keyboard.nextDouble();

Sort.sort( score );
/*
Sort a = new Sort();
a.sort( score );
*/
System.out.println("The scores are" );
for(index = 0; index< score.length; index++)
System.out.println(score[index]);

2009年6月1日 星期一

"Lab Array"

Study Display 6.1, and then write a program that can sort numbers in ascending order.


-----
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;
System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index <>
score[index] = keyboard.nextDouble();
for( index = score.length-1; index >-1 ; --index){
for (int j = 0; j <>
if(score[index] > score[j]){
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}
System.out.println("The scores are" );
for(index = 0; index<>
System.out.println(score[index]);
}

Lab: Static Method II

Define a Complex class with a static method for computing complex addition. Use (2+3i)*(4+5i) in your test.



public class ADT {
private int real, image ;
public ADT(){
}
public ADT(int real , int image) {
this.real = real;
this.image = image;
}
public ADT mult(ADT ADT2){
ADT ans = new ADT(0,0) ;
ans.real = this.real * ADT2.real + this.image * ADT2.image;
ans.image = this.image * ADT2.real + this.real * ADT2.image;
return ans;
}
public String toString(){
return real + "+" + image + "i";
}
}

-----

public class StaticMethodII {
public static void main(String[] args) {
ADT f1, f2;
f1 = new ADT(2,3);
f2 = new ADT(4,5);
System.out.println("f1 = " + f1.toString());
System.out.println("f2 = " + f2.toString());
System.out.println("f1 x f2 = " + f1.mult(f2).toString());
}