JAVA

星期五, 三月 31, 2006

max

程式碼

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Untitled2 {
public static void main(String[] args)throws IOException {
BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
double a=0;


String input;

System.out.println("請輸入十個數");
int count;
double b=Double.parseDouble(keyboard.readLine());
for(count=1;count<10;count++) { input=keyboard.readLine(); a=Double.parseDouble(input); System.out.println("input="+a);
if[b小於a]
{
b=a;
}
else
b=b;
System.out.println("最大數為"+b);
}
}

星期一, 三月 27, 2006

P161 project7

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Untitled1 {
public static void main (String[] arge)throws IOException
{
int a=1;
BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
//System.out.println(y);
String y=keyboard.readLine();
int yy=Integer.parseInt(y);
double w=1,r=1,z=1;
for(int i=1;i<100;i++)
{ w=w*yy;

r=r*i;

z=z+w/r;


}
System.out.println("e^"+yy+"="+z);
}
//System.out.println(y);

}

星期日, 三月 26, 2006

3.20homework










public class Untitled1 {
public static void main (String[] args)
{
System.out.println("累加數列");
double a=0,b=1,c=0,d=0;
for(int i=1;i<100;i++)
{
a=b+c;
b=c;
c=a;
d=a/b;
System.out.println(a+"值"+d);
}

}
}

星期一, 三月 20, 2006

作業3/13-2

程式碼
package s9325116;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class s9325116{
public s9325116(){
}
public static void main(String[] args)throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter some nonnegative numbers:");
System.out.println("Mark the end with a negaive number.");
System.out.println("I will compare Max and min");
double max=-1,min=-1,num=0;
int count=0;
String input="";
while(num >= 0)
{
input = keyboard.readLine();
num = Double.parseDouble(input);
if ((max==-1)||(num>=max)&&amp;amp;num>=0)
max = num;
if((min==-1)||(num<=min)&&num>=0)
min = num;
count++;
}

if (count==0)
System.out.println("No numbers entered.");
else
{
System.out.println("There are "+count+" numbers read.");
System.out.println("The max is "+max+" and the min is "+min);
}
}
}

作業3/13-1稅率

程式碼

package welcome;

/**
*

Title:


*
*

Description:


*
*

Copyright: Copyright (c) 2006


*
*

Company:


*
* @author not attributable
* @version 1.0
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Untitled3 {
public static void main(String[] args)throws IOException {
BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
System.out.println("輸入所得");
String inputIncome=keyboard.readLine();
int netIncome=Integer.parseInt(inputIncome);
double tax;
if(netIncome<=370000)
tax=netIncome*0.06;
else if ((netIncome>370000)&&(netIncome<=990000))
tax=netIncome*0.13-25900;
else if ((netIncome>990000)&&(netIncome<=1980000))
tax=netIncome*0.21-105100;
else if ((netIncome>1980000)&&(netIncome<=3720000))
tax=netIncome*0.3-283300;
else
tax=netIncome*0.4-655300;
System.out.println("Tax due="+tax);
}


}

星期一, 三月 13, 2006

keyboard

package aaa;

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 podas followed by");
int numberOfPods=Integer.parseInt(keyboard.readLine());
System.out.println("the number of peas in a pod:");


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


程式結果

作業

程式:

import javax.swing.JOptionPane;
public class 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);
}
}

星期一, 三月 06, 2006

把hate改成love

package aaa;


public class Untitled1 {
public static void main(String[] args)
{
String sentence="I hate text processing!";
int position=sentence.indexOf("hate");
String ending=
sentence.substring(position+"hate".length());
System.out.println(sentence);
sentence=sentence.substring(0,position)+"love"+ending;
System.out.println("The changed string is:");
System.out.println(sentence);

}
}

程式結果
I hate text processing!

The changed string is:

I love text processing!

Display 1.7

package aaa;


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


程式結果
I hate text processing!

The world"hate"starts at index2

The changed string is:

I adore text processing!

homework 2/27

public class s9325116
{
public static void main (String[] arg)
{
double personweightpound=150,personweightkilogram;
double run6MPHMET=10;
double basketballMET=8;
double sleepMET=1;
double run6MPHminutetime=30;
double basketballtimeminute=30;
double sleeptimehour=6;
personweightkilogram=personweightpound/2.2;

System.out.println("The person's weight is "+personweightkilogram+" kilograms.");

System.out.println("He runs 6 MPH for 30 munites burned "+0.0175*300*personweightkilogram+" calories.");

System.out.println("He plays basketball for 30 munites burned "+0.0175*240*personweightkilogram+" calories.");

System.out.println("He sleep for 6 hours burned "+0.0175*360*personweightkilogram+" calories.");

System.out.println("");

System.out.println("He totaly burned "+0.0175*(300+240+360)*personweightkilogram+" calories.");
}


執行結果
alories / Minute = 0.0175 * MET * Weight(Kg)
A 150-pound person is 68.18181818181817Kg
Running 6 MPH 30 minutes burns : 357.9545454545455 cal.
Basketball 30 minutes burns : 286.3636363636363 cal.
Sleeping 6 hours burns : 429.54545454545456 cal.
Total burns : 1073.8636363636363 cal.