Java 练习 之 转义字符 字符

简单的字符处理

1
2
3
4
5
6
7
8
public class ZiFu {
public static void main(String args[]){
char a = 'A';
char b = '\u003a';
System.out.println("第一个字符类型的值等于"+a);
System.out.println("第二个字符类型的指等于"+b);
}
}

gowhich得到的结果是:

1
2
第一个字符类型的值等于A
第二个字符类型的指等于:

做个小小实例

计算圆的面积:

1
2
3
4
5
6
7
8
9
public class YuanMianJi {
public static void main(String args[]){
final double PI = 3.14;
int R = 5;
double ymj = PI * R * R;
System.out.println("圆的面积等于"+ymj);
}

}

得到的结果是:

1
圆的面积等于78.5

转义字符的处理

1
2
3
4
5
6
public class ZhuanYiZiFu {
public static void main(String args[]){
System.out.println("Hello \n World");
System.out.println("Hello \\n Word");
}
}

得到的结果是:

1
2
3
Hello 
World
Hello \n Word