课堂源码

package com.gaden.ch02;
//基本数据类型
public class Test {
    public static void main(String[] args) {
        boolean b1 = false;
        if(b1){
            System.out.println("么么哒");
        }else{
            System.out.println("emmmm...");
        }

        int i1 = 10;
        System.out.println(i1);

        char c1 = 'a';
        System.out.println(c1);

        char c11 = 97;

        char c22 = (char) (c11+1);

        System.out.println(c22);

        float f1 = 3.14f;
        double d1 = 3.23767823;

        int i2 = 20;
        long  l = i2;//自动类型转换
        long l1 = 200;
        int i3  = (int) l1;//强制类型准换

        double d2 = 20.3;
        long  l4 = 200;
         int i4 = 10;

         int i5 = i4/2;

         long l5 = l4/2;

         double b3 = d2/2.0;

         float f4 = 2.3f;

         float f5 = (float) (f4/2.0);

         String str = "Hello \\ World!!";
         System.out.println(str);

         String str1 = "Hello";
         String str2 = "World!!";
         //在String类型中 ‘+’ 代表着连接,而非真正意义上的相加
         System.out.println(str1+str2);

         int a = 2;
         String s = "abc";
         int b = 3;
          String ss = a+s;

          int id = 54423;
          String id2 = id+"";

         System.out.println(a+s+b);//2abc3
         System.out.println(a+b+s);//5abc
         System.out.println(s+a+b);//abc23

         String str3 = "www:baidu:com";
         System.out.println(str3.charAt(5));
         String s10 = str3.split(":")[1];
         System.out.println(s10);

         String sss = str3.concat("www");
         System.out.println(sss);

         boolean b10 = str3.startsWith("baidu");
         str3.endsWith(".com");

         str3.indexOf("baidu");
         System.out.println(str3.indexOf("baidu"));

         System.out.println(b10);


    }

}





//运算符

package com.gaden.ch02;
/**
 * 
 * @author gaden
 *阿萨德了交流附件b
 */
public class TestAri {
    public static void main(String[] args) {
        //--------------------------算术运算符的测试----------------------------------------
        //除 /
        int i0 = 12;
        int j0 = i0/5;
        double d = i0/5;
        double d1 = i0/5.0;

        System.out.println(j0);
        System.out.println(d);
        System.out.println(d1);

        //取模:% 取余数 结果的符号取决于被摸数
        int i1 = 12%5;
        int i2 = -12%5;
        int i3 = -12%(-5);
        int i4 = 12%(-5); 
        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println(i4);


        //前++:先自增1 后运算
        //后++:先运算  后自增1
        int myInt1 = 10;
        int myInt2 = myInt1++;
        System.out.println(myInt1);
        System.out.println(myInt2);

        int myInt3 = 10;
        int myInt4 = ++myInt3;
        System.out.println(myInt3);
        System.out.println(myInt4);

        //前--:
        //后--:

        //String 的+运算
        String str1 = "么么";
        String str2 = "哒";      
        System.out.println(str1+str2);

        int a1 = 5;
        int a2 = 2;
        String s = "abc";

        System.out.println(a1+a2+s);
        System.out.println(a1+s+a2);
        System.out.println(s+a1+a2);

        //不要把==写成=
        boolean b1= false;
        if(b1=true){
            System.out.println("结果为真");
        }else{
            System.out.println("结果为假");
        }

        //-------------------------逻辑运算符的测试----------------------------------------
        boolean b2 = true;
        boolean b3 = false;
        System.out.println(b2 & b3);//flase
        System.out.println(b2 && b3);//flase
        System.out.println(b2 | b3);//true
        System.out.println(b2 || b3);//true
        System.out.println(b2 ^ b3);//true

        //& 和 && 的区别
        int i5 = 10;
        if(b3 & (i5++) > 0){
            System.out.println("心情不错");
        }else{
            System.out.println("心情不好");
        }
        System.out.println(i5);

        if(b3 && (i5++) > 0){
            System.out.println("心情不错");
        }else{
            System.out.println("心情不好");
        }
        System.out.println(i5);

        //三元运算

        int i = 20;
        int j = 25;
        int max = (i > j) ? i : j;
    }

}

//字符串

package com.gaden.ch02;

public class TestCh02 {
    public static void main(String[] args) {
        int i1 = 10;
        float f1 = 2.0f;
        double d1 = 2.0;
        char c1 = 'a';
        char c2 =97;
        int c3 = c1+c2;

        String s ="aaa";
        int a = 3;
        int b = 2;

        //String类型中的‘+’代表着字符串的连接,而非真正意义上的相加。
        System.out.println(s+a);//aaa3
        System.out.println(s+b);//aaa2

        System.out.println(a+b+s);//5aaa
        System.out.println(a+s+b);//3aaa2
        System.out.println(s+a+b);//aaa32

        double d5 = 534333;

        String id = d5+"";

        String str = "www:baidu:com";
        //判断某个字符串是否以某个特定的字符结尾
        boolean b4 = str.endsWith(":com");
        boolean b5 = str.startsWith("www");
        System.out.println(b4);

        System.out.println(str.charAt(5));
        System.out.println(str.indexOf("w"));
        System.out.println(str.indexOf("e"));

        System.out.println(str.split(":")[1]);

        System.out.println(str.length());
        if(str.indexOf("e") != -1){

        }else{

        }
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值