JAVA

名稱:

星期一, 10月 31, 2005

N pruduct

package aaaaa;

import javax.swing.JOptionPane;

public class aaa{
public static void main(String[] args) {
int i;
int ans=1;
int c;

while(1>=0)
{String number=JOptionPane.showInputDialog(" Enter a number");
c= Integer.parseInt(number);

ans=c*ans;
if (ans>=0)
{System.out.println("pruduct is "+ans);
}

else System.out.println("Finished");



}




}
}

費式級數的例子

所謂的費式級數,就是 0,1,1,2,3,5,8,13,21...and go on

他是數列前兩項之和,為他下一項的和.

大自然中最有明的例子就是生育的例子.

假設兔子一次只會生下一隻兔子,並且生下的兔子不會死亡.且生下的兔子還會在生下兔子
pair 數
則 1 1
1 1
1 1 2
1 1 1 3
1 1 1 1 1 1 5


另外蜜蜂的家族表

如果是公蜜蜂的話,他的長輩就是媽媽一隻照顧, 如果是母蜜蜂的話,他的長輩則是父母照顧

因此

父母 爺奶 祖父母 祖父母的父母 祖父母的爺爺奶奶
每一隻公蜜蜂 1 2 3 5 8
每一隻母蜜蜂 2 3 5 8 13

以上也是一個費事數列的例子


另外遠古的鸚鵡羅 他的排法就是

以正方形 邊長 不斷的擴張出去

邊長 1 1 2 3 5 並且繞者他角落不斷的旋轉出去

這個高中的時候有話過相關的圖形,應該也算是吧!

66667
52237
51137
54447
88888 概念圖 = =

EXP

public class EXP {

public static void main(String[] args)throws IOException
{


double i,n1=1,n2=0,count1=1,count2=1,sum1=0,sum2=1;
String sum=JOptionPane.showInputDialog("n=");
double n = Integer.parseInt(sum);
for (i=0;i<100;i++){
count1=count1*n;
count2=count2*n1;
sum1=count1/count2;
n2=n2+count1;
sum2=sum2+sum1;n1++;
}
System.out.println("N= " +n);
System.out.println("exp(N) is = " +sum2 );
}
}

星期一, 10月 24, 2005

Fibonacci

public class Fibonacci {
public Fibonacci() {
}

public static void main(String[] args) {
double f0 = 1, f1 = 1, f2 = 0, ratio = 0;
System.out.println("1" + " ratio is " + "?");
System.out.println("1" + " ratio is " + "1");
for (int i = 0; i < 100; i++) {
f2 = f0 + f1;
ratio = (double) f2 / f1;
f0 = f1;
f1 = f2;
System.out.println(f2 + " ratio is " + ratio);
}
}
}

Lab Max Min

import java.io.*;
public class Max_min {
public Max_min() {
}
public static void main(String[] args)throws IOException{
System.out.println("please enter the count of a list of number\n"+" (two at least) ");
double max,min;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
int next = Integer.parseInt(inputString);
System.out.println("/////////////");
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);
int i=next;
if(next2>next1)
{max=next2;
min=next1;}
else{
max=next1;
min=next2;
}
for(i=next;i>2;i--){
BufferedReader keyboard3= new BufferedReader(new InputStreamReader(System.in));
String inputString3 = keyboard3.readLine();double next3 = Double.parseDouble(inputString3);
if((next3>next1)&&(next3>next2))
max=next3;
else if ((next3
min=next3;
}
System.out.println("max="+max);
System.out.println("min="+min);
}
}

If - Else 2

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class I_E2 {
public static void main(String[] args)throws IOException {
BufferedReader Keyboard=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the number:");
int n=Integer.parseInt(Keyboard.readLine());
if (n<0)
System.out.println("n < 0");
else if ((0 <= n)&&(n< 100))
System.out.println("0 <= n < 100");
else {
System.out.println("n >= 100");
}
}
}

Homework 2.5 2.7

import javax.swing.JOptionPane;
public class Homework2.5
{
public static void main(String[] args)
{
String purchasePrice=JOptionPane.showInputDialog("Enter the purchase price:");
double P=Double.parseDouble(purchasePrice);
String salvageValue=JOptionPane.showInputDialog("Enter the salvage value:");
double S=Double.parseDouble(salvageValue);
String numberOfYears=JOptionPane.showInputDialog("Enter the number of years:");
double Y=Double.parseDouble(numberOfYears);
double D=(P-S)/Y;
System.out.println("The yearly depreciation for the item = "+D);
}
}

Homework 2.7

import javax.swing.JOptionPane;
public class Homework 2.5
{
public static void main(String[] args)
{
String priceOfItem=JOptionPane.showInputDialog("Enter price of item\n (from 25 cents to a dollar, in 5-cent increment):");
int price=Integer.parseInt(priceOfItem);
System.out.println("You bought an item for "+price+" cents and gave me a dollar,\n so your change is");
int q=0,d=0,n=0;
int change=100-price;
if(change>=25)
{
q=change/25;
change=change%25;
}
if(change>=10&&change<25)
{
d=change/10;
change=change%10;
}
if(change>=5&&change<10)
{
n=change/5;
change=change%5;
}
System.out.println(q+" quarters,\n"+d+" dimes, and\n"+n+" nickels.");
}
}

Display 3.1

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Dusplay {
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) && (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);
}
}

星期一, 10月 17, 2005

LAB

package untitled10;

/**
*

Title:


*
*

Description:


*
*

Copyright: Copyright (c) 2005


*
*

Company:


*
* @author not attributable
* @version 1.0
*/
public class Untitled1 {
public static void main(String[] arg ) {
double netIncome, tax, fivePercentTax, tenPercentTax;
netIncome= 50000;

System.out.println("Enter net income=50000.\n"
+ "Do not include a dollar sign or any commas.");


if (netIncome <= 15000) tax = 0; else if ((netIncome > 15000) && (netIncome <= 30000)) //tax = 5% of amount over $15,000 tax = (0.05*(netIncome - 15000)); else //netIncome > $30,000
{
//fivePercentTax = 5% of income from $15,000 to $30,000.
fivePercentTax = 0.05*15000;
//tenPercentTax = 10% of income over $30,000.
tenPercentTax = 0.10*(netIncome - 30000);
tax = (fivePercentTax + tenPercentTax);
}

System.out.println("Tax due = " +tax);


}
}

Scanner

package untitled7;

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





public class Untitled1 {
public static void main(String [] arg) throws IOException{




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

System.out.println("Enter the number of pods followed by");
System.out.println("the number of peas in a pod:");

int numberOfPods=Integer.parseInt(keyboard.readLine());
int peasPerPod=Integer.parseInt(keyboard.readLine());
int totalNumberOfPeas=numberOfPods*peasPerPod;
System.out.print(numberOfPods+" pods and ");
System.out.println(peasPerPod+" peas per pod.");
System.out.println("The total number of peas ="+totalNumberOfPeas);
}
}

星期一, 10月 03, 2005

Display1.7 Lab 3

Display 1.7
LAB3


Display 1.7

public class LAB5 {
public static void main (String[] args) {
String sentense = "I hate processing";
int position = sentense.indexOf("hate");
String ending =
sentense.substring(position +"hate".length());
System.out.println("01234567890123456789012");
System.out.println(sentense);
System.out.println("The word \"hate\" starts at index"+ position);
sentense = sentense.substring(0 ,position) +"adore"+ending;
System.out.println("The change string is:");
System.out.println(sentense);
}
}


Lab 3


public class LAB5 {
public static void main (String[] args) {
String sentense = "I hate YOU";
int position = sentense.indexOf("hate");
String ending =
sentense.substring("hate ".length());

System.out.println(sentense);

sentense = sentense.substring(0 ,position) +"like"+ending;
System.out.println("The change string is:");
System.out.println(sentense);



}
}

星期六, 10月 01, 2005

homework 3

public class homework3 {
public static void main(String[] args) {
int Running = 10;
int basketball= 8;
int sleeping = 1;
double weight;
weight=150/2.2;
System.out.println("the man burned "+weight*0.0175*(Running*30+basketball*30+sleeping*360)+" Calories");
}
}

這次作業比之前的lab2清楚的多,所以很快的也做好了!

Homework3