gpt4 book ai didi

java - LinkedList主程序(是否可以要求用户输入数据并以linkedList方式存储......?)

转载 作者:行者123 更新时间:2023-12-01 23:27:16 24 4
gpt4 key购买 nike

以下是我的问题

1. In an ArrayList we used below function to ask user to input 20 data, so, how to rewrite this ?
2. Function using the LinkedList method?
3. Is it possible to ask user to input the data and stored it in a LinkedList way...?

代码:

public static void main(String[] args) 
{
ArrayList al = new ArrayList(20);
Scanner in = new Scanner(System.in);
Student st;
String name, id;

float cgpa;
for(int i=0; i<20; i++)
{
System.out.println("Name : ");
name = in.next();
System.out.println("ID : ");
id = in.next();
System.out.println("CGPA : ");
cgpa = in.nextFloat();

st = new Student(name, id, cgpa);
al.add(i,st);
}

最佳答案

这就是您所需要的:

LinkedList al = new LinkedList(); 

关于java - LinkedList主程序(是否可以要求用户输入数据并以linkedList方式存储......?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19804992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com