|
查看: 1227|回复: 3
|
Java Control Structure
[复制链接]
|
|
|
有个问题,这是要用control stucture
我做不到哦!我选B,它读A的东西。到底我错在哪里?
题目是这样的:
A company would like to increase the staff salary
Status Pekerja Tempoh Bekerja Peratus Kenaikan
Sepenuh masa (A) Kurang 5 tahun 0.025
Sepenuh masa (A) 5 tahun dan ke atas 0.05
Sambilan (B) Kurang 5 tahun 0.02
Sambilan (B) 5 tahun dan ke atas 0.03
Write out a program which will count the new salary after the increase by using input
我的code
import java.io.*;
class gaji_pekerja
{
public static void main(String args[])throws IOException
{
BufferedReader stdin=new BufferedReader (new InputStreamReader(System.in));
String inData,inData2,status,tempoh1,tempoh2,chars;
int tempoh,tempoh2a;
double gaji,gaji2,gaji_baru,gaji_baru2,total,total2;
do
{
System.out.println("Masukkan status (A-sepenuh masa, B-sambilan : )");
status=stdin.readLine();
{
if(status.equals("A" ));
{
System.out.println("Masukkan tempoh:" );
tempoh1=stdin.readLine();
tempoh=Integer.parseInt(tempoh1);
System.out.println("Masukkan gaji: RM" );
inData=stdin.readLine();
gaji=(Double.valueOf(inData)).doubleValue();
}
if(tempoh<5)
{
gaji_baru= gaji*0.025;
total=gaji+gaji_baru;
System.out.println("Gaji baru:"+ total);
}
if(tempoh>5)
{
gaji_baru= gaji*0.05;
total=gaji+gaji_baru;
System.out.println("Gaji baru:" + total);
}
}
System.out.print("Adakah, anda ingin bersambung?(yes or no)" );
chars=stdin.readLine();
} while(chars.equals("yes" ));
if(status.equals("B" ));
{
System.out.println("Masukkan tempoh:" );
tempoh2=stdin.readLine();
tempoh2a=Integer.parseInt(tempoh2);
System.out.println("Masukkan gaji: RM" );
inData2=stdin.readLine();
gaji2=(Double.valueOf(inData2)).doubleValue();
}
if(tempoh2a<5)
{
gaji_baru2= gaji2*0.02;
total2=gaji2+gaji_baru2;
System.out.println("Gaji baru:"+ total2);
}
if(tempoh2a>5)
{
gaji_baru2= gaji2*0.03;
total2=gaji2+gaji_baru2;
System.out.println("Gaji baru:" + total2);
}
}
}
[ 本帖最后由 科技小女孩 于 3-3-2009 08:27 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 3-3-2009 10:03 PM
|
显示全部楼层
我没有compile 你的code
只是,if statement 后面你怎么直接 ";" ?
然后哦,5年了的怎样?
还有就是做什么你不用else... |
|
|
|
|
|
|
|
|
|
|
发表于 3-3-2009 10:27 PM
|
显示全部楼层
原帖由 科技小女孩 于 3-3-2009 08:25 PM 发表 
有个问题,这是要用control stucture
我做不到哦!我选B,它读A的东西。到底我错在哪里?
题目是这样的:
A company would like to increase the staff salary
Status Pekerja ...
if (status.equals("A")) {
....
else if (status.equals("B")) {
...
} |
|
|
|
|
|
|
|
|
|
|
发表于 3-3-2009 10:32 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|