我需要我的程序幫助。我需要在兩個()中使用變量「三」,「四」,但我不知道如何。 請幫忙。如何在其他功能中使用變量
public class Main {
public static void main(String[] args) {
one()
}
public static void one(){
Integer three;
Integer four;
Integer five;
three = 3;
four = 4;
two();
}
public static void two(){
five = three + four;
System.out.println(five);
}
}
你定義他們的路,他們是當地只有你聲明它們在方法聲明。他們作爲類變量,而不是任何方法,那麼你可以在方法中實例化或設置它們的值。 – csmckelvey
將這些變量聲明爲類變量。然後創建你的班級的對象並給他們打電話。先了解基本的課程,對象,功能。 –
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html – Radiodef