horsemanship世界

星期一, 3月 13, 2006

Homework4

作業1:
import java.io.*;
public class work {
public static void main(String[] args) throws IOException
{
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("請輸入你的年收入:");
String number1 = keyboard.readLine();
int x = Integer.parseInt(number1);
double y,z=0;

if(x<370000)
{
z = x*0.06;
}
else if( x < 990000)
{
y = x * 0.13;
z = y - 25900;
}
else if( x < 1980000)
{
y = x*0.21;
z = y-105100;
}
else if( x < 3720000)
{
y = x*0.3;
z =y-283300;
}
else
{
y=x*0.4;
z=y-655300;
}
System.out.println("你應繳交" + z + "元的所得稅.");
}
}

結果:
請輸入你的年收入:
3720001
你應繳交832700.4000000001元的所得稅.
=====================================================================
作業2:
import java.io.*;
public class work {public static void main(String[] args) throws IOException{BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a nonnegative number per line.");
System.out.println("請輸入任意數字,並且只能輸給正數,且最後一個數為負數。");
double max=-1,min=-1,num=0;int count=-1;
String input;
while(num >= 0){input = keyboard.readLine();
num = Double.parseDouble(input);
if ((max==-1num>=max)&&(num>=0))max = num;
if ((min==-1num<=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("最大數 "+max);System.out.println("最小數"+min);
}}}

結果:
請輸入任意數字,並且只能輸給正數,且最後一個數為負數。
266
999
5
64
31
-2
There are 5 numbers read.
最大數 999.0
最小數5.0

0 Comments:

張貼留言

<< Home