我很新的Java和搜查通過以前問這並沒有幫助我的問題的問題...如何在類之間傳遞變量?
我如何通過int變量年齡和字符串名稱,從主類的人類?
package engineers;
import java.util.Scanner;
public class Engineers {
public static void main(String[] args) {
// TODO code application logic here
Scanner scan = new Scanner(System.in); //declaration and ssignment of scanner
System.out.println("Enter name: "); //name prompt
String name = scan.next(); //reads name input from user
System.out.println("Enter age: "); //age prompt
int age = scan.nextInt(); //reads age input from user
System.out.println("Pay check amount: ");
double salary = scan.nextDouble();
Person person = new Person();
}
private static class Person {
/**
* A default constructor
*/
public Person() {
}
/**
* method for displaying the computation result
*/
double avgSalary = 40000 * Math.sqrt(Math.exp(0.04295 * age + 0.141));
public void showData(int age, double pay){
System.out.printf("%s earns $%4.3f for age %3d.\n", name, (pay*Math.sqrt(age)*.15), age);
}//end method showData
}
}
您通過年齡以同樣的方式,你傳遞'String'到'println'或浮點值'Math.exp'你的代碼是充滿了如何做到這一點的例子。 –