嗨,需要帮助伙伴们!新手在这里。如何在Studentinfo中打印所有学生名? BOBbless [英] Hi, Need Help Guys! Newbie Here. How Can I Print All Studentname In Studentinfo? BOBbless

查看:76
本文介绍了嗨,需要帮助伙伴们!新手在这里。如何在Studentinfo中打印所有学生名? BOBbless的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Public  class  StudentInfo {
String studentName;
String barrowedBooks;
字符串日期;
String expiredDate;


void listOfStudent(){
如何在StudentInfo中打印所有studentName

}

}


Public class InputStudentInfo {

StudentInfo studentReg,justin,gian;

justin = new StudentInfo();
gian = new StudentInfo();
studentReg = new StudentInfo();



justin.studentName = Justin Lazaro;
justin.barrowedBooks =( English,Math);


gian.studentName = Gian Acuna;
gian.barrowedBooks = 数学;

}

解决方案

我建​​议使用阵列 [ ^ ]。



  class  InputStudentInfo {

//
public void main( String [] args)
{
// 声明要存储的ArrayList学生列表
ArrayList< studentInfo> students = new ArrayList< studentInfo> ;;

StudentInfo student = new StudentInfo();
// 1
student.studentName = Justin Lazaro;
student.barrowedBooks =( English,Math);
// 添加到列表
students.Add(student);
// 2
student = new StudentInfo();
student.studentName = Gian Acuna;
student.barrowedBooks = 数学;
students.Add(学生);
// 等。

// 进一步......
// 用于(...)循环
// 迭代学生的集合
}
}





如需了解更多信息,请参阅: for-each循环 [ ^ ]



顺便说一下:为什么要将日期声明为字符串?

  String  date; 
String expiredDate;



Java知道日期数据类型 [ ^ ]。


for(int i = 0; i< studentName.size(); i ++){

System.out.println (studentName.get(i));



}







无法在arraylist中打印所有值

Public class StudentInfo {
String studentName;
String barrowedBooks;
String date;
String expiredDate;


void listOfStudent(){
  "How can i print all studentName in StudentInfo " 

}

}


Public class InputStudentInfo {

	StudentInfo studentReg, justin, gian;
		
		justin = new StudentInfo();
		gian = new StudentInfo();
		studentReg = new StudentInfo();
		
	
			
		justin.studentName = "Justin Lazaro";
		justin.barrowedBooks = ("English, Math");
		
		
		gian.studentName = "Gian Acuna";
		gian.barrowedBooks = "Math";
		
}

解决方案

I'd suggest to use ArrayList[^].

class InputStudentInfo {
 
    //
    public void main (String[] args)
    {
        //declare ArrayList to store students list
        ArrayList<studentInfo> students = new ArrayList<studentInfo>;

        StudentInfo student = new StudentInfo();
        //1
        student.studentName = "Justin Lazaro";
        student.barrowedBooks = ("English, Math");
        //add to list
        students.Add(student);     
        //2	
        student = new StudentInfo();
        student.studentName = "Gian Acuna";
        student.barrowedBooks = "Math";
        students.Add(student);
        //etc.

        //further...
        // use for(...) loop
        // to iterate through the collection of student
    }
}



For further information, please see: The for-each loop[^]

By The Way: Why do you declare date as as a string?

String date;
String expiredDate;


Java knows date data type[^].


for (int i=0; i< studentName.size(); i++){
System.out.println(studentName.get(i));

}



bro i cant print all value in arraylist


这篇关于嗨,需要帮助伙伴们!新手在这里。如何在Studentinfo中打印所有学生名? BOBbless的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆