写的不好不要笑我!欢迎大家指正。- import java.util.Scanner;
- class GoodDemo {
- public static void main(String[] args) {
- run();
- }
- public static void run () {
- Scanner sc = new Scanner(System.in);
- Good g = new Good();
- System.out.println("请输入您的姓名:");
- if (g.setName(sc.nextLine()) == false) {
- System.out.println("请输入您的真实姓名!\n\n\n\n");
- run();
- } else {
- run2(g);
- }
- }
- public static void run2 (Good g) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入您的年龄:");
- if (g.setAge(sc.nextInt()) == false) {
- System.out.println("您输入的年龄不正确(范围在 0 ~ 130 之间):");
- run2(g);
- } else {
- g.print();
- System.out.println("\n\n\n\n您的电脑即将【关机】,如果不想关机请不要关闭本窗口,并大声呼喊三声我是傻叉!!!\n\n\n\n\n\n\n\n");
- }
- }
- }
- class Good {
- private String name;
- private int age;
- public boolean setName (String name) {
- if (name.length() > 3 || name.length() < 2) {
- return false;
- }else {
- this.name = name;
- return true;
- }
- }
- public boolean setAge (int age) {
- if (age >= 0 && age <= 130) {
- this.age = age;
- return true;
- } else {
- return false;
- }
- }
- public void print () {
- System.out.println(name);
- if (name.equals("高斯林") || name.equals("詹姆士")) {
- System.out.println("我叫 " + name + " , 是个非常的牛叉!\n今年 " + age + " , 早就已成家!");
- } else {
- System.out.println("我叫 " + name + " , 是个大傻叉!\n今年 " + age + " , 至今没有家!");
- }
- }
- }
复制代码
|
|