나는 웹 사이트에 이미 주어진 다양한 제안을 시도했다. 그러나 솔직히 나는 그것을 고칠 무언가를 couldnt.다양한 기능에서 변수를 사용하려면 어떻게해야합니까? 자바
기본적으로 수락에서 만든 변수를 사용하려고하면 다른 기능에서 사용할 수 없습니다. 이 문제를 해결할 수있는 간단한 해결책이 있습니까? (주 코드를 변경하지 않고)
import java.util.Scanner;
class x4Salary
{
Scanner input = new Scanner(System.in);
public void accept()
{
System.out.println("Please input the name of the teacher");
String name = input.next();
System.out.println("Please input the address ");
String adress = input.next();
System.out.println("Please input the phone number");
long num = input.nextLong();
System.out.println("Please input the subject specialization");
String subjectSpecialization = input.next();
String subS = subjectSpecialization;
System.out.println("Please input the Monthly Salary");
long sal = input.nextLong();
if(sal>175000)
{
tax();
}
display();
double tax = 0.0;
}
public void tax()
{
System.out.println("Your current salary is : " + sal);
tax = sal + ((5/sal)*100);
System.out.println("The salary + Tax : " +tax);
display();
}
public void display()
{
System.out.println("The name of the teacher : " + name);
System.out.println("The Address of the teacher :" +adress);
System.out.println("The Phone number of the Teacher: "+num);
System.out.println("The Subject Specialization of the Teacher" + subS);
System.out.println("The Monthly salary of the teacher" +sal + tax);
}
}
* "이미 웹 사이트에서 여러 가지 제안을 시도했습니다." 보았던 3 개의 쓰레드에 링크하십시오. –