Monday, October 31, 2005

更改版的lab1

import javax.swing.JOptionPane;
public class pan1{

public static void main(String[] args)
{int x=1;

String a = JOptionPane.showInputDialog("打一個數字");
int n = Integer.parseInt(a);
while(n>=0){
x*=n;
a = JOptionPane.showInputDialog("打一個數字");
n = Integer.parseInt(a);
}
System.out.println(x);


}
}

10月31日lab1

package pan;
import javax.swing.JOptionPane;
public class pan1{

public static void main(String[] args)
{int x=1;
int n=1;
while(n>=0){
String a = JOptionPane.showInputDialog("打一個數字");
n = Integer.parseInt(a);
if (n>=0) x*=n;
}
System.out.println(x);


}
}


Fibonacci numbers.

package pan;

public class pan1{

public static void main(String[] args)
{
double a=0,b=1,c=0,d=0,e=0,f=0;
System.out.println(a);
System.out.println(b);
for(int i=0;i<=50;i++)
{ c=a+b;
System.out.print(c);
e=c/b;
System.out.println("公比是"+e);
a=c;
d=b+c;
System.out.print(d);
f=d/c;
System.out.println("公比是"+f);
b=d; } } }


Fibonacci numbers


















兔子的生態可以表示這個級數
















樹枝生長的圖也可以表示這個級數

One plant in particular shows the Fibonacci numbers in the number of "growing points" that it has. Suppose that when a plant puts out a new shoot, that shoot has to grow two months before it is strong enough to support branching. If it branches every month after that at the growing point, we get the picture shown here.

A plant that grows very much like this is the "sneezewort": Achillea ptarmica.















自然界中到處可見費氏數列的蹤跡。樹技上的分枝數,多數花的瓣數都是費氏數:火鶴 1、百合 3,梅花 5,桔梗常為 8,金盞花 13,…等等。費氏數列也出現在松果上。一片片的鱗片在整粒松果上順著兩組螺線排列:一組呈順時針旋轉,另一組呈反時針,請參 考 http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#pinecones 網頁上的圖;仔細瞧瞧,順時針螺線的排列數目是 8,反時針方向則為 13,而另一組常出現的數字是「5 8」。向日葵也是一樣,常見的螺線數目為「3455」,較大的向日葵的螺線數目則為「89 144」,更大的甚至還有「144233」。這些全都是費氏數列中相鄰兩項的數值。

Monday, October 24, 2005

最大最小值

package aaa;
import java.io.*;
public class aaa {
public static void main(String[] args)throws IOException{
double max,min;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
BufferedReader keyboard1= new BufferedReader(new InputStreamReader(System.in));
String inputString1 = keyboard1.readLine();
double next1 = Double.parseDouble(inputString1);
BufferedReader keyboard2= new BufferedReader(new InputStreamReader(System.in));
String inputString2 = keyboard2.readLine();
double next2 = Double.parseDouble(inputString2);
BufferedReader keyboard4= new BufferedReader(new InputStreamReader(System.in));
String inputString4 = keyboard4.readLine();
double next4 = Double.parseDouble(inputString4);

if(next2>next1)
{max=next2;
min=next1;}
else{
max=next1;
min=next2;
}
if (next4>max)
max=next4;
else if(next4
{min=next4;
}
System.out.println("最大的值是"+max);
System.out.println("最小的值是"+min);
}
}

執行的結果


Lab If-Else (2)

package aaa;
import javax.swing.JOptionPane;
public class aaa
{
public static void main(String[] args)
{


String myString=JOptionPane.showInputDialog("Enter a number: ");
int n = Integer.parseInt(myString);


if(n<0){ n= " +n+ ">=0 & n<100){
System.out.println("n介於0和100之間,n= " +n+ " , ");
}
else if( 100<=n )
{
System.out.println("n大於100,n= " +n+ " , ");
}
}
}

執行結果

Sunday, October 23, 2005

Project 2.05

package aaa;
import javax.swing.JOptionPane;
public class aaa
{
public static void main(String[] args)
{
String purchaseString = JOptionPane.showInputDialog(
"Enter purchase of price:");
double p = Double.parseDouble(purchaseString);
String salvageString = JOptionPane.showInputDialog(
"Enter salvage value:");//copy from icesun
double s = Double.parseDouble(salvageString);
String yearServiceString = JOptionPane.showInputDialog(
"Enter expected number of years of service:");
double y = Double.parseDouble(yearServiceString);
double sum = (p-s)/y;//copy from icesun
JOptionPane.showMessageDialog(null,"The yearly depreciation ="+sum);

}
}

Monday, October 17, 2005

Display 3.1

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Untitled1 {
public static void main(String[] args ) throws IOException
{ double b,c,d;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter net income.\n" + "Do not include a dollar sign or any commas.");
double a = Double.parseDouble(keyboard.readLine());
if (a<=15000) b=0; else if ((a>15000) &&amp; (a<=30000))
b=(0.05*(a-15000));
else
{c=0.05*15000;
d=0.1*(a-30000);
b=c+d;
}
System.out.println("Tax due =" +b);

}

}

結果

JAVA Display 2.6

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Untitled1 {
public static void main(String[] args ) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of pods follwed by");
System.out.println("the number of peas in a pod");
int b = Integer.parseInt(keyboard.readLine());
int c = Integer.parseInt(keyboard.readLine());
int d=b*c;
System.out.println(b+" pods and");
System.out.println(c+" peas per pod");
System.out.println("the total number of peas=" +d);
}

}

結果

java JOptionpane

import javax.swing.JOptionPane;
public class Untitled1 {
public static void main(String[] args) {

String abc = JOptionPane.showInputDialog("Enter a number");
System.out.print(abc);
}

}

跑出一個視窗以後,輸入你要輸入的數值(456)










最後的結

Monday, October 03, 2005

display 1.7

public class Untitled2 {
public static void main(String[] args)
{
String a="I hate text processing!";
int b= a.indexOf("hate");
String ending =
a.substring(b+"hate".length());
System.out.println("01234567890123456789012");
System.out.println(a);
System.out.println("the word \"hate\" starts at index"+b);
a=a.substring(0,b)+"adore"+ending;
System.out.println("the changed string is:");
System.out.println(a);
}
}



執行結果


codemate

package welcome;

public class Untitled2 {
public static void main(String[] args)
{
String a="I hate you";
int b= a.indexOf("hate");
String ending =
a.substring(b+"hate".length());
System.out.println("The line of text to be change is:");
System.out.println(a);
a=a.substring(0,b)+"love"+ending;
System.out.println("I have rephrased that line to read:");
System.out.println(a);
}
}


執行結果

Saturday, October 01, 2005

homework3

程式碼

public class home3
{
public static void main(String[] args)
{
double poundweight=150;
double rate=0.0175;
double a;
double b;
double c;
System.out.println("A person is 150 pound = "+poundweight/2.2+" kilograms.");
a=rate*10*30*poundweight/2.2;
System.out.println("Running 6 MPH for 30 minutes is consumming "+a+" calories.");
b=rate*8*30*poundweight/2.2;
System.out.println("Playing basketball for 30 minutes is consumming "+b+" calories.");
c=rate*1*6*60*poundweight/2.2;
System.out.println("Sleeping for 6 hours is comsumming "+c+" calories.");
System.out.println("The total number of calories burned is "+(a+b+c)+".");
}
}

顯示
A person is 150 pound = 68.18181818181817 kilograms.
Running 6 MPH for 30 minutes is consumming 357.9545454545455 calories.

Playing basketball for 30 minutes is consumming 286.3636363636363 calories.
Sleeping for 6 hours is comsumming 429.54545454545456 calories.
The total number of calories burned is 1073.8636363636363.