
正文
java学号的代码 java中学号怎么定义
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
编写一个java程序,要求输入自己的学号姓名
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test222 {
public static void main(String[] args) throws IOException {
int i, j;
String a;
BufferedReader str = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("请输入学号:");
a = str.readLine();
System.out.println("学号为:" + a);
str = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入姓名:");
a = str.readLine();
System.out.println("姓名为:" + a);
}
}
望采纳~~
相关问答
Q1: 求java中类似学生信息管理系统中按学号,按姓名排序的代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Sort {
public static void main(String[] args) {
Student p1 = new Student(1001, "小明", 20);
Student p2 = new Student(1002, "小红", 21);
Student p3 = new Student(1003, "小黑", 19);
ListStudent list = new ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的学号进行升序排列
if (o1.getId() o2.getId()) {
return 1;
}
if (o1.getId() == o2.getId()) {
return 0;
}
return -1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list, new ComparatorStudent() {
/*
* int compare(Student o1, Student o2) 返回一个基本类型的整型, 返回负数表示:o1 小于o2,
* 返回0 表示:o1和o2相等, 返回正数表示:o1大于o2。
*/
public int compare(Student o1, Student o2) {
// 按照学生的年龄进行升序排列
if (o1.getAge() o2.getAge()) {
return 1;
}
if (o1.getAge() == o2.getAge()) {
return 0;
}
return -1;
}
});
write(list);
}
public static void write(ListStudent list) {
for (Student s : list) {
System.out.println(s.getId() + "\t" + s.getName() + "\t"
+ s.getAge());
}
}
}
public class Student {
private int id ;
private String name;
private int age;
//构造方法
public Student(int id,String name,int age){
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Q2: 求一份可以提供很多学生学号排序的Java代码
小众的treeset + 策略模式 帮你实现一个.
import java.util.TreeSet;
public class Test {
/**
* 测试,TreeSet 1去重 2比较器排序 3比较器中小众的扩展三目表达式应用
*
* @param args
*/
public static void main(String[] args) {
TreeSetStudent set = new TreeSetStudent(new CompareUtils());
set.add(new Student(1, "remind"));
set.add(new Student(3, "lucy"));
set.add(new Student(2, "lird"));
set.add(new Student(3, "houty"));
set.add(new Student(4, "tina"));
set.add(new Student(7, "houty"));
for (Student stu : set) {
System.out.println(stu);
}
}
}
/**
* pojo类
*
* @author remind
*
*/
public class Student {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + "]";
}
}
import java.util.Comparator;
/**
* 比较器
*
* @author remind
*
*/
public class CompareUtils implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
return (o1.getId() o2.getId()) ? 1 : (o1.getId() == o2.getId()) ? 0 : -1;
}
}
Q3: 怎么编写一个简单Java应用程序,输出自己的姓名和学号?
下面是一个java 小程序实现的\x0d\x0aimport java.awt.*;//引入包\x0d\x0aimport java.applet.Applet;//引入包\x0d\x0apublic class Output extends Applet//定义类\x0d\x0a{\x0d\x0a //定义变量\x0d\x0a private String name;\x0d\x0a private int num;\x0d\x0a //初始化\x0d\x0a public void init()\x0d\x0a {\x0d\x0a name = getParameter("vname");\x0d\x0a num = Integer.parseInt(getParameter("vnum"));\x0d\x0a }\x0d\x0a //输出\x0d\x0a public void paint(Graphics g)\x0d\x0a {\x0d\x0a g.drawString ("姓名:"+name+";学号:"+num,20,30);\x0d\x0a }\x0d\x0a}\x0d\x0a\x0d\x0a相应的html文件\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a
java学号的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java中学号怎么定义、java学号的代码的信息别忘了在本站进行查找喔。







