小编Llo*_*ron的帖子

如何从java中的另一个方法访问对象?

我有我在create()方法中创建的对象numberlist,我想访问它,所以我可以在question()方法中使用它.

有没有办法做到这一点,我错过了,或者我只是弄乱了什么?如果没有,我该怎么做才能让我获得与下面相同的功能?

private static void create() {
    Scanner input = new Scanner(System.in);

    int length,offset;

    System.out.print("Input the size of the numbers : ");
     length = input.nextInt();

     System.out.print("Input the Offset : ");
     offset = input.nextInt();

    NumberList numberlist= new NumberList(length, offset);




}


private static void question(){
    Scanner input = new Scanner(System.in);

    System.out.print("Please enter a command or type ?: ");
    String c = input.nextLine();

    if (c.equals("a")){ 
        create();       
    }else if(c.equals("b")){
         numberlist.flip();   \\ error
    }else if(c.equals("c")){
        numberlist.shuffle(); \\ error
    }else if(c.equals("d")){
        numberlist.printInfo(); \\ error
    }
}
Run Code Online (Sandbox Code Playgroud)

java

6
推荐指数
1
解决办法
1万
查看次数

智能手机的最低屏幕分辨率是多少?

智能手机的最低屏幕分辨率是多少?是 320x480 吗?

frontend android smartphone

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

frontend ×1

java ×1

smartphone ×1