Java学习笔记

来自软件实验室
跳转至: 导航搜索
public class sss{
//创建一个类(类是储存代码的容器,所有代码必须放在一个类中   public:公有的;class:定义一个类;sss:类名)
public static void main(String[] lalala){
//此行为方法(static:在类级别定义,此类所有实例共享;void:标记方法不返回任何值;String[] ...:数组)
System.out.println("徐浩傻比");
//标准输出(println:打印一行,且以后自动换行;print:不换行)
char a = '徐';
char b = '浩';
double c=1.23456D
//定义a的值为“徐”,b为“浩”
//java的数据类型:byte字节型, short短整型, int整形, long长整形(后加L), float单精度浮点型(后加F), 
//double双精度浮点型(后加D), char字符型(一个) boolean(布尔型,即对错)
System.out.println("who is shabi?"+a+b);
boolean e=101>300;
boolean f=1<300;
//boolean的值只有对错
if(e){
System.out.println("傻逼");
}if(f){
System.out.println("逗比");
}
//选择语句,如果e是对的则执行第一个,如果f是对的执行第二个
double g=100;
if(g>120){
System.out.println("徐浩傻比");
}else{
//否则
System.out.print("徐浩大傻逼");
}
int i= 129;
byte p=(byte)i;
//强制数据类型转换,但可能损失精度
System.out.println(Integer.toBinaryString(i));
//这什么暂时不懂
System.out.println(Integer.toBinaryString(p));
//同上
System.out.println((p));
int x=56;
while (x>10){
x=x-6;
System.out.println(x);
}
//while循环,在满足()内条件时循环执行{}内代码
System.out.println(x);
for (int shabi=0; shabi<10;shabi=shabi+1){
System.out.println("shabi is now    "+shabi);
}
//for循环,与while类似
int sos=1;
System.out.println("now is before the loop");
while (sos<5){
System.out.println("now is in the loop");
System.out.println("sos 的值是"+sos);
sos=sos+1;
}
System.out.println("now is over the loop");
int QAQ=99;
while(QAQ>0){
System.out.println("炸弹将在"+QAQ+"秒后爆炸");
QAQ=QAQ-1;
}
System.out.println("炸弹炸了");
//以上为对循环的练习
String shabimen[]=new String[]{"徐浩","王凯","荆松凯","汤佳伟","张钰罗华"};
//建立数组
int poi=shabimen.length;
//将长度赋值给变量
System.out.println(poi);
int s=3;
while(s>0){
if(s>2){
System.out.print("a");
}
if(s==2){
System.out.print("b c");
}
if(s==1){
System.out.print("d");
}
if(s>1){
System.out.print("-");
}
s=s-1;
}
//小练习:输出a-b c-d
}
}