我需要我的程序帮助。我需要在两个()中使用变量“三”,“四”,但我不知道如何。 请帮忙。如何在其他功能中使用变量
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