标签:
public class Login {
/**
* 判断学生登录是否成功
* @param name
* @param password
* @return
*/
public boolean login(String name,String password){
if(name.equals("jbit")&&password.equals("bdqn")){
return true;
}else
return false;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入用户名:");
String name = input.next();
System.out.println("请输入密码:");
String password = input.next();
Login lg=new Login ();
boolean flag=lg.login(name, password);
if(flag){
System.out.println("登录成功!");
}else{
System.out.println("用户名或密码错误!");
}
}
}
public class Student {
private String name; //姓名
private int age; //年龄
private String sex; //性别
private String school; //学校
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;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
}
public class StudentDao {
/**
* 模拟插入学生数据到数据库
* @param stu
*/
public void insertStudent(Student stu){
String name=stu.getName();
int age=stu.getAge();
String sex=stu.getSex();
String school=stu.getSchool();
System.out.println("\n将该学生信息成功写入到数据库");
System.out.println(name+" "+age+" "+ sex +" "+school);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生姓名:");
String name = input.next();
System.out.println("请输入学生年龄:");
int age = input.nextInt();
System.out.println("请输入学生性别:");
String sex = input.next();
System.out.println("请输入学生学校:");
String school = input.next();
Student stu = new Student();
stu.setName(name);
stu.setAge(age);
stu.setSchool(school);
stu.setSex(sex);
StudentDao stuDao =new StudentDao();
stuDao.insertStudent(stu);
}
}
public class GetProNo {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入年份: ");
int year = input.nextInt();
System.out.print("请选择产品类型(1. 台式机 2. 笔记本 3. 其他)");
int type = input.nextInt();
int random = (int)(Math.random() * 1000); //产生3位随机数
String productNo = year + "0" + type + random; //产生产品编号
System.out.println("\n该固定资产编号是: " + productNo);
}
}
public class DeDate {
public static void main(String[] args) {
System.out.print("请输入一个日期(月/日/年): ");
Scanner input = new Scanner(System.in);
String date = input.next();
int pos1 = date.indexOf("/");
int pos2 = date.lastIndexOf("/");
int length = date.length();
String month = date.substring(0, pos1);
String day = date.substring((pos1 + 1), pos2);
String year = date.substring((pos2 + 1), length);
System.out.println("\n\n" + year + "年" + month + "月" + day + "日");
}
}
标签:
原文地址:http://www.cnblogs.com/mentorStudio/p/4803691.html