java编程基础中的一些小细节

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a =3,b;
		b=a++;//先赋值给B,再进行a++运算
		System.out.println("a="+a+",b="+b);
	}

}

输出:a=4,b=3


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a =3,b;
		b=++a;//先进行a++运算,再赋值给b
		System.out.println("a="+a+",b="+b);
	}

}

输出:a=4,b=4


public class Demo {
	public static void main(String args[]){
		int x=4270;
		x=x/1000*1000;//x为int型数据类型,所以在进行运算后也是int型数据。
		System.out.println(x);
	}
}

输出:4000



public class Demo1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(5%1);
		System.out.println(1%5);
		System.out.println(2%5);
		System.out.println(3%5);
		System.out.println(4%5);
		System.out.println(5%5);
		System.out.println(8%-5);
		System.out.println(-5%9);
		System.out.println(-18%7);
		/*
		 * 左边小于右边结果是左边,
		 * 左边等于右边结果是0
		 * 右边等于1结果是0
		 * 
		 */
		/*
		 *
		 * 对于出现负数的情况 看%百分号左边的数字,左边是负数
		 * 结果就是负数,左边是正数,结果就是正数,运算方法不变
		 */

	}

}

输出:

0
1
2
3
4
0
3
-5
-4



public class Demo2 {
	public static void main(String[] args){
		System.out.println("hello word");
		System.out.println("\"hello word\"");//输出带引号的hello word
		System.out.println("hello \n word");
		System.out.println("hello\tword");
		System.out.println("hello\bword");



		/*
		 * 转义字符:通过	\	反斜杠来转变后面的字母或者符号的含义
		 * \n:换行
		 * \b:退格
		 * \r:回车符号
		 * \t:水平跳格符,tab键
		 */

	}
}

输出:

hello word
"hello word"
hello 
 word
hello word
helloword

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值