我知道这很容易,但我是java新手。我们正在学习if,else和课堂上的while循环。我不知道如何写这个问题中的“if”部分。所以,如果我需要声明一个新的字符串名称或类似的东西,我不会。
//****************************************************************************************
//
// Computes the amount of raise and the new
// salary for an employee. The current salary
// and a performance rating (A string: Excellent", "Good" or "Poor") are input.
//****************************************************************************************
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary1
{
public static void main (String[] args)
{
double currentSalary; //employee's current salary
double raise; // amount of the raise
double newSalary; // new salary of the employee
String rating; // performance rating
Scanner scan = new Scanner(System.in);
System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the Performance rating (Excellent, Good, or Poor): ");
rating = scan.next();
// Compute the the raise using if....
newSalary = (currentSalary + raise);
//print the results
NumberFormat money = NumberFormat.getCurrencyInstance();
System.out.println();
System.out.println("Current Salary: " + money.format(currentSalary));
System.out.println("Amount of your raise: " + money.format(raise));
System.out.println("Your new salary: " + money.format(newSalary));
System.out.println();
}
}
答案 0 :(得分:-1)
if
语句的伪代码如下所示:
if(/*boolean value*/) {
// code to execute when the part in parenthesis is true
} else {
// code to execute when the part in parenthesis is false
}
在上面的伪代码段中,/*boolean value*/
可以替换为可以评估为true
或false
的任何内容。这包括:
==
,!=
,<
,>
,>=
,<=
)||
,&&
)作为旁注,您可以使用!
获取其中任何一个的反布尔值。
值得一提的是,语句的else
部分是完全可选的。
this将帮助您开始比较Java中的字符串(使用将返回布尔值的方法。