자바 if else 질문이요!
-
게시물 수정 , 삭제는 로그인 필요
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary
{
public static void main (String[] args)
{
double currentSalary; // employee's current salary
double raise; // amount of the raise
double newSalary; // new salary for 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 raise using if ...
if (rating == 1)
raise = currentSalary * .06;
else if(rating == 2)
raise = currentSalary * .04;
else if(rating == 3)
raise = currentSalary * .015;
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();
}
}
저기서 1은 excellent 2 는 good 3은 poor
인데요
컴파일이 안되네요.. 도와주세요.
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary
{
public static void main (String[] args)
{
double currentSalary; // employee's current salary
double raise; // amount of the raise
double newSalary; // new salary for 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 raise using if ...
if (rating == 1)
raise = currentSalary * .06;
else if(rating == 2)
raise = currentSalary * .04;
else if(rating == 3)
raise = currentSalary * .015;
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();
}
}
저기서 1은 excellent 2 는 good 3은 poor
인데요
컴파일이 안되네요.. 도와주세요.
#자바 if문 #자바 if else #자바 if 조건 여러개 #자바 if문 탈출 #자바 if문 예제 #자바 if문 조건 여러개 #자바 if문 return #자바 if문 break #자바 ifpresent #자바 if문 한줄