Java日常练习题

要求每个方法必须有注释

1、循环打印出字符串“中华人民共和国”每个汉字
String str = “中华人民共和国”; //定义一个字符串
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
System.out.println(ch);
}
2、现在字符串“123” 转换其为整数型,并计算与200的和
3、现有字符串“12.3” 转换为双精度型,并计算与20.21的和
4、把整数型的10转换为字符串,并与“个中国人”相连接,并打印出来
5、键盘输入数字并判断与22是否相等,如果相等则打印“您输入正确”,否则输出“你输入错误”
6、键盘输入汉字并按空格进行切分,打印输出
例如:输入"中国 人民 共和" 则按空格进行切分后分别打印出”中国“ “人民” “共和”
这块注意要点:
(1)代码 Scanner in =new Scanner(System.in);
String c = in.next(); 可以接收汉字
(int b=in.nextInt(); 可以接收数字)
(2)写代码时要注意如果没有空格时代码的兼容性问题
7、现有字符串“云南高黎贡山国家级自然保护区的工作人员” 打印“国家”所在字符串的位置,并截取其后面的所有字符
8、用户登录时需要用户输入验证码才能登录,现在验证码为“ABcD” ,如何进行判断用户输入验证码的正确性。
注意要点:验证码是不区分大小的
9、现在有几个标题
“hive离线数据库” “hadoop优化课程” “友盟网大数据系统” “大数据shell脚本”
查找标题中包含“大数据” 的标题,并打印出来
10、任意一段文字查找关键字所在的所有位置
替换:替换所有文章中的某个汉字
11、下面为菜单
首页
视频课程
面试集锦
编程教程
新闻资讯
名师专区
VIP专区
想调整“视频课程” 与 “名师专区”位置,如何操作

12、计算1-100当中能5整除但不能被10整除的数的乘积
13、计算1-100当中能被3整除但不能被12整除的数的和
14、计算1-100所有数据和,但不包含20
15、当前有1-100的数据,但仅计算1-10的数据的和
用两种方法计算,其中一种方法需要用到break
16、用while语句计算1到100的和
17、当前班里有5个人,总分分别为80 70 65 90 求出
分数最大的委任为”班长“ 分数最低的为“普通学生”

自己写的答案会有一些错误 帮忙纠正哈
hh
package day6;

import java.security.spec.RSAOtherPrimeInfo;
import java.util.Scanner;

public class StringTest2 {
public static void main(String[] args) {

    wu();
}


/**
 * 分别打印中华人民共和国
 */

public static void one() {
    String one = "中华人民共和国";
    for (int i = 0; i < one.length(); i++) {
        char n = one.charAt(i);
        System.out.println(n);
    }
}

/**
 * 现在字符串“123” 转换其为整数型,并计算与200的和
 */
public static void two() {
    String i = "123";
    int one = Integer.parseInt(i);
    System.out.println(one + 200);
}

/**
 * 现有字符串“12.3” 转换为双精度型,并计算与20.21的和
 */
public static void doubleSum() {
    String n = "12.3";
    double one = Double.parseDouble(n);
    System.out.println(one);
    double i = one + 20.21;
    System.out.println(i);

}

/**
 * 把整数型的10转换为字符串,并与“个中国人”相连接,并打印出来
 */
public static void lianJie() {
    int i = 10;
    String n = String.valueOf(i);
    //System.out.println(n);
    System.out.println(n + "个中国人");
}

/**
 * 键盘输入数字并判断与22是否相等,如果相等则打印“您输入正确”,否则输出“你输入错误”
 */
public static void pangDuan() {
    int a = 22;
    Scanner sc = new Scanner(System.in);
    System.out.print("请输入一个整数:");
    int b = sc.nextInt();
    if (b == a) {
        System.out.println("您输入正确");
    } else {
        System.out.println("您输入错误");
    }
}

/**
 * 键盘输入汉字并按空格进行切分,打印输出
 */
public static void daYin() {
    Scanner ch = new Scanner(System.in);
    System.out.print("请输入:");
    String c = ch.next();
    if (c == "#") {

    }
    String wx[] = c.split("#");
    for (int i = 0; i < wx.length; i++) {
        System.out.println(wx[i] + "\t");

   }
}

/**
 * 现有字符串“云南高黎贡山国家级自然保护区的工作人员” 打印“国家”所在字符串的位置,并截取其后面的所有字符
 */
public static void ziFu() {
    String i = "云南高黎贡山国家级自然保护区的工作人员";
    int n = i.indexOf("山");
    System.out.println(n);
    String one = i.substring(8, 19);
    System.out.println(one);
}

/**
 * 用户登录时需要用户输入验证码才能登录,现在验证码为“ABcD” ,如何进行判断用户输入验证码的正确性。
 * 注意要点:验证码是不区分大小的
 */
public static void dengLu() {
    String one = "ABcD";
    Scanner in = new Scanner(System.in);
    System.out.print("请输入:");
    String a = in.next();
    if (a.equalsIgnoreCase(one)) {
        System.out.println("输入正确");
    } else {
        System.out.println("输入错误");
    }
     }

/**
 * 现在有几个标题
 * “hive离线数据库” “hadoop优化课程”  “友盟网大数据系统”   “大数据shell脚本”
 * 查找标题中包含“大数据” 的标题,并打印出来
 */
public static void biaoTi() {
    String[] one = {"hive离线数据库", "hadoop优化课程", "友盟网大数据系统", "大数据shell脚本"};
    Scanner in = new Scanner(System.in);
    System.out.print("请输入查找内容:");
    String a = in.next();
    if (a == "友盟大数据系统" || a == "大数据shell脚本") {
        System.out.println();

    } else {
        System.out.println("查找内容没有");
    }


}

/**
 * 任意一段文字查找关键字所在的所有位置
 * 替换:替换所有文章中的某个汉字
 */
public static void tiHuan() {
    String words = " 任意一段文字,查找,关键字,所在的,所有位置";
    int one = words.indexOf("在");
    System.out.println(one);
    String words2 = words.replaceAll(",", "?");
    System.out.println(words2);
}

/**
 * 下面为菜单
 * 首页
 * 视频课程
 * 面试集锦
 * 编程教程
 * 新闻资讯
 * 名师专区
 * VIP专区
 * 想调整“视频课程”  与 “名师专区”位置,如何操作
 */
public static void caiDan() {
    int a = Integer.parseInt("首页");
    int b = Integer.parseInt("视频课程");
    int c = Integer.parseInt("面试集锦");
    int d = Integer.parseInt("编程教程");
    int e = Integer.parseInt("新闻资讯");
    int f = Integer.parseInt("名师专区");
    int g = Integer.parseInt("VIP专区");


}

/**
 * 计算1-100当中能5整除但不能被10整除的数的乘积
 */

public static void wu() {
    int sum = 1;
    for (int i = 1; i <= 100; i++) {
        if (i % 5 == 0 && i % 10 != 0) {
            sum = sum * i;
            // System.out.println(sum);
        }
    }
    System.out.println(sum);
}

/**
 * 计算1-100当中能被3整除但不能被12整除的数的和
 */
public static void he() {
    int sum = 0;
    for (int i = 1; i <= 100; i++) {
        if (i % 3 == 0 && i % 12 != 0) {
            sum = sum + i;
            // System.out.println(sum);
        }
        System.out.println(sum);
    }
}

/**
 * 计算1-100所有数据和,但不包含20
 */
public static void baoKou() {
    int sum = 0;
    for (int i = 1; i <= 100; i++) {
        if (i == 20) {
            continue;
        }
        sum = sum + i;
    }
    System.out.println(sum);
}

/**
 * 当前有1-100的数据,但仅计算1-10的数据的和
 * 用两种方法计算,其中一种方法需要用到break
 */
public static void shuJu() {
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
        sum = sum + i;
    }

    System.out.println(sum);
}

public static void shuJU2() {
    int sum = 0;
    for (int i = 1; i <= 100; i++) {
        if (i == 11) {
            break;
        }
        sum = sum + i;
    }
    System.out.println(sum);
}

/**
 * 用while语句计算1到100的和
 */
public static void while1() {
    int sum = 0;
    int i = 1;
    while (i <= 100) {
        sum = sum + i;
        i++;
    }
    System.out.println(sum);
}

/**
 * 当前班里有5个人,总分分别为80 70 65 90 求出
 * 分数最大的委任为”班长“  分数最低的为“普通学生”
 */
public static void fenShu() {
    Scanner in = new Scanner(System.in);
    System.out.print("请输入一个整数:");
    int a = in.nextInt();
    if (a >= 90) {
        System.out.println("班长");
    } else if (a < 90 && a > 65) {
        System.out.println("学生");
    } else {
        System.out.println("普通学生");
    }

}

/**
 * 现在有几个标题
 * “hive离线数据库” “hadoop优化课程”  “友盟网大数据系统”   “大数据shell脚本”
 * 查找标题中包含“大数据” 的标题,并打印出来
 */
public static void test() {
    String[] one = {"hive离线数据库", "hadoop优化课程", "友盟网大数据系统", "大数据shell脚本"};
    for (int i = 0; i < one.length; i++) {
        int a = one[i].indexOf("大数据");
        if (a != -1) {
            System.out.println(one[i]);
        } else {
            System.out.println("没有");
        }
    }
}

}

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值