佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1227|回复: 3

Java Control Structure

[复制链接]
发表于 3-3-2009 08:25 PM | 显示全部楼层 |阅读模式
有个问题,这是要用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 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 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 | 显示全部楼层
原帖由 winmxaa 于 3-3-2009 10:27 PM 发表



if (status.equals("A") {
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;....
else if (status.equals("B") {
&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;...
}


你写完答案出来就不好玩了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 16-12-2025 05:13 PM , Processed in 0.131014 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表