简体   繁体   中英

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. 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. so replace

Arrays.toString(list.toArray());

With

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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