java的代码



package com.jereh.demo;

import java.util.Arrays;
import java.util.Scanner;

public class Demo10 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //验证一个数字是否是回文数
        //比较数字的第一位跟最后一位是否相等,第二位跟倒数第二位是否相等.......
        //输入一个数字
        Scanner input=new Scanner(System.in);
        //提示用户输入的数字格式
        System.out.println("*************请输入一个五位数以上的数字************");
        //接收输入的数字
        int i=input.nextInt();//接收到的数字
        int length=0;//数组的长度
        int k=i;//用于获取位数
        //得到整数的位数
        while(k>0){
            k/=10;
            length++;
        }
        //声明一个数组,长度是数的位数
        int[] ints=new int[length];
        //遍历数组进行赋值
        for(int j=0;j<ints.length;j++) {
            ints[j]=i%10;
            i/=10;
        }
        System.out.println(Arrays.toString(ints));
        //验证是否是回文数
        for(int j=0;j<ints.length;j++) {
            //验证两位数是否相等
            if(ints[j]!=ints[length-1-j]) {
                System.out.println("该数字不是回文数");
                return;
            }
        }
        System.out.println("该数字是回文数");
    }

}


package com.jereh.demo;

public class Demo {
    
    static int totalScore;
    /**
     * 部门总工有三十个员工,每个人的分数相加,取平均
     * @param args
     */
    public static void main(String[] args) {
        //1.声明一个数组的同时,给数组去分配空间
        int[] scores={5,6,7,8,9};
        //3.数组元素进行赋值
        //总分数
        System.out.println(totalScore);
        for(int i=0;i<scores.length;i++) {
            scores[31]=250;
            System.out.println(scores[31]);
//            scores[i]=69+i;
//            //分数相加
//            totalScore+=scores[i];
//            //每位员工的分数
//            System.out.println("员工"+(i+1)+"的分数是:"+scores[i]);
        }
        //取30个员工的平均分
        System.out.println("员工的平均分是:"+totalScore/30);
        
    }
}


 1 package com.jereh.javabase.ch07;
 2 
 3 import java.util.Scanner;
 4 
 5 public class StudentSearch {
 6     
 7     //定义一个数组去存储学生信息
 8     public String[] names=new String[5];
 9     //接收用户输入的信息
10     public Scanner input=new Scanner(System.in);
11     
12     /**
13      * 得到输入的学生名字
14      */
15     public void addNames() {
16         //循环5次,得到名字
17         for(int i=0;i<names.length;i++) {
18             //提示用户输入
19             System.out.print("请输入学生的名字");
20             names[i]=input.next();
21         }
22     }
23     
24     /**
25      * 展示信息
26      */
27     public void show() {
28         // 提示信息
29         System.out.println("本班学生列表");
30         // 展示所有的学员信息
31         for (int i = 0; i < names.length; i++) {
32             System.out.print(names[i] + "	");
33         }
34     }
35     
36     /**
37      * 得到用户输入的查询条件
38      */
39     public void searchAndShow() {
40         //提示我们输入要查询的开始位置
41         System.out.print("
请输入开始查找的位置");
42         //开始位置
43         int start=input.nextInt();
44         //提示我们输入查询的结束位置
45         System.out.print("请输入结束查找的位置");
46         //结束位置
47         int end=input.nextInt();
48         //提示我们输入要查询的学员名字
49         System.out.print("请输入要查询的学员姓名");
50         //学员名字
51         String name=input.next();
52         //关闭scanner
53         input.close();
54         
55         //查询的结果打印在控制台
56         boolean isFound=search(start,end,name);
57         if(isFound) {
58             //找到了
59             System.out.println("找到了");
60         } else {
61             //没找到
62             System.out.println("没有该学生");
63         }
64     }
65     
66     public boolean search(int start,int end,String name) {
67         //提示信息
68         System.out.println("***查询结果****");
69         //开始查找是否存在学员信息
70         for(int i=start-1;i<end;i++) {
71             //判断当前这个元素是否跟传入的元素内容相等
72             if(name.equals(names[i])) {
73                 return true;
74             }
75         }
76         return false;
77     }
78 
79     public static void main(String[] args) {
80         // TODO Auto-generated method stub
81         //构造对象
82         StudentSearch search=new StudentSearch();
83         //使用对象
84         //1.添加数据
85         search.addNames();
86         //2.展示数据
87         search.show();
88         //3.查询结果
89         search.searchAndShow();
90     }
91 
92 }

练习题目:

使用面向对象的思想描述论坛用户

问题描述:

某公司要开发“天天灌水论坛”,请使用面向对象的思想,设计注

册用户信息

要求:

1、分析用户的属性和方法,设计用户类

2、设计带参构造函数实现属性赋值

3、编写测试方法实现信息输出

参考分析思路:

用户类:

属性: 用户昵称,密码,性别,年龄,注册时间,等级

方法:个人信息展示

运行效果:

原文地址:https://www.cnblogs.com/wztblog/p/1241169116a.html