java的基础题

一、ArrayList应该如何创建

ArrayList<String>StringList=new ArrayList<String>();

二、ArrayList的概念

长度可以改变的数组(集合对象)。

三、全局变量与局部变量

全部变量:在整个类范围定义的,所有方法都可见。

局部变量:在方法内部定义的。

四、foreach循环

for(String  s:List){

System.out.printin(s)

}

五、next与nextint nextline的区别。

  1. nextInt() :接受从键盘输入的int数据

  2. hasNextInt(); 判断是否输入为整型 int 

  3. nextLine():   返回按 enter键 之前输入的字符

六、学生类的代码

package com.lenove.www;


/**
 * 
 * @author lenovo
 *
 */
public class Student {
private int age;
private double height;
private double weight;
private String name;
private String classroom;


public Student(int age, double height, String name, String classroom,double weight) {
super();
this.age = age;
this.height = height;
this.name = name;
this.classroom = classroom;
this.weight= weight;
}


public int getAge() {
return age;
}


public void setAge(int age) {
this.age = age;
}


public double getHeight() {
return height;
}


public void setHeight(double height) {
this.height = height;
}


public double getWeight() {
return weight;
}


public void setWeight(double weight) {
this.weight = weight;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getClassroom() {
return classroom;
}


public void setClassroom(String classroom) {
this.classroom = classroom;
}


public Student() {


}


}

package com.lenove.www;


import java.util.ArrayList;


public class StudentText {
public static void main(String[] args) {
ArrayList<Student> list = new ArrayList<>();
Student s1 =new Student();
s1.setName("小明");
s1.setAge(16);
s1.setClassroom("软件174");
s1.setHeight(175);
s1.setWeight(55);
Student s2 = new Student(18, 175, "小花", "软件175",60);
Student s3 = new Student(18, 175, "小红", "软件174",50);
Student s4 = new Student(18, 175, "小华", "软件176",30);
Student s5 = new Student(18, 175, "小小", "软件178",55);

list.add(s1);
list.add(s2);
list.add(s3);
list.add(s4);
list.add(s5);

    list.remove(1);
for (Student b : list) {
System.out.println("姓名"+b.getName()+"体重"+b.getWeight()+"身高"+b.getHeight());

}
for(int i=0;i<list.size();i++) {
Student s = new Student();
System.out.println(s.getClassroom());

};
   
}
}



阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭