题 题 题 题

一.


public class DaJie {
    public static void main(String[] args) {
        String a = "打劫!我有枪";
        dj(a);
    }
 
    private static void dj(String a) {
        String [] stu = {"枪"};
        for (int i = 0; i < stu.length; i++) {
            if (a.contains(stu[i])){
                a = a.replace(stu[i],"*");
                System.out.println(a);
            }
        }
    }
}

二.

public class BeiJing {
    public static void main(String[] args) {
        String a = "北京欢迎你";
        String[] str = {"北京"};
        String[] str1 = {"你"};
 
        for (int i = 0; i < str.length; i++) {
            if(a.contains(str[i])){
                a = a.replace(str[i],"郑州");
                a = a.replace(str1[i],"你们");
                System.out.println(a);
            }
        }
    }
}

三.

public class SiXiang {
    public static void main(String[] args) {
        //定义的字符串
        String a = "面向对象是以对象为核心..编程思想";
        //用for循环获取下标
        for (int i = 0; i < a.length(); i++) {
 
        }
        //charAt是获取字符串第i个字符
        System.out.println(a.charAt(0));
        System.out.println(a.charAt(a.length()-1));
    }

}

四.

public class San {
    public static void main(String[] args) {
        double a=3.1415926;
        System.out.println("a = " + a);
        String str = String.valueOf(a);
        System.out.println("字符串str 的值: " + str);
    }

}

五.


public class Kong {
    public static void main(String[] args) {
        String s="qwqe";
        if (s.length()>0) {
            System.out.println("此字符串不为空");
            System.out.println("s = " +  s.charAt(0));
            System.out.println("字符串的长度为" + s.length());
            System.out.println("第一个字符" +  s.charAt(0));
        }else {
            s="hello word";
            System.out.println("此字符串为空赋值为 hello word");
            System.out.println("字符串的长度为" + s.length());
            System.out.println("第一个字符" +  s.charAt(0));
        }
    }

}

六.

ublic class WeiZhi {
    public static void main(String[] args) {
        String a= "abca";
 
        System.out.println("a的下标为" + a.indexOf("a"));
        System.out.println("a的下标为" + a.lastIndexOf("a"));
 
        if (a.equals(a.charAt(0)) == a.equals(a.charAt(a.length()-1)))  {
            a="*bc*";
            System.out.println("a = " + a);
        }
    }

}

七.

public class IntAndInteger {
    public static void main(String[] args) {
        int num = 123;
        Integer a = new Integer(num);
        System.out.println(a.toString());
 
        Integer a2 = new Integer("123");
        System.out.println(a2.toString());

 
        Boolean b1 = new Boolean("true11");
        System.out.println(b1);
 
        int c = 11;
        // 字符串连接符转换
        String str = c + "";
        Integer d = new Integer(11);
        System.out.println(str);
 
        String str1 = "123";
        Integer e1 = Integer.parseInt(str1);
        System.out.println("e1 = " + e1);
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值