简体   繁体   English

为什么我的java代码不打印出数组列表?

[英]Why doesn't my java code print out the array list?

package booking;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class CarProfile {

    static int year;
    static int cylinders;
    static int plateNum;

    public static void main(String[] args) {
        int reg = 1;
        ArrayList <CarProfile> list = new ArrayList <CarProfile>();

        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);

        while(reg == 1) {                   
            System.out.println("Enter manf. year");
            year = sc.nextInt();
            System.out.println("Enter num. of cyl");
            cylinders = sc.nextInt();
            System.out.println("Enter plateNum");
            plateNum = sc.nextInt();
            System.out.println("If you wish to register another car press 1, otherwise press anything");
            reg = sc.nextInt(); 
        }

        Arrays.toString(list.toArray());    
    }
}

This is the code.这是代码。 I also tried to use a for loop with System but didn't get any luck there either.我也尝试在 System 中使用 for 循环,但也没有运气。 So what am I missing here?那么我在这里错过了什么? I don't know what else to type, it is a really simple question.我不知道还能输入什么,这是一个非常简单的问题。

You aren't calling System.out.println on the code, The code doesn't knows its suppose to print it out.您没有在代码上调用System.out.println ,代码不知道它应该打印出来。 so replace所以更换

Arrays.toString(list.toArray());

With

System.out.println(Arrays.toString(list.toArray()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM