-
邏輯運算符
查看全部 -
強制類型轉(zhuǎn)化:( 數(shù)據(jù)類型 ) 數(shù)值
查看全部 -
?目標類型能與源類型兼容,如 double 型兼容 int 型,但是 char 型不能兼容 int 型
目標類型大于源類型,如 double 類型長度為 8 字節(jié), int 類型為 4 字節(jié),因此 double 類型的變量里直接可以存放 int 類型的數(shù)據(jù),但反過來就不可以了
查看全部 -
變量名由多單詞組成時,第一個單詞的首字母小寫,其后單詞的首字母大寫,俗稱駱駝式命名法(也稱駝峰命名法),如 myAge;Java 變量名的長度沒有限制
查看全部 -
public class HelloWorld {
? ? public static void main(String[] args) {
// 定義一個長度為 3 的字符串數(shù)組,并賦值初始值
String[] hobbys = { "sports", "game", "movie" };
System.out.println("循環(huán)輸出數(shù)組中元素的值:");
// 使用循環(huán)遍歷數(shù)組中的元素
for(int i = 0;i < hobbys.length;i++) {
? ? System.out.println(hobbys[i]); //不能將hobbys[i]中i的值忘掉T_T
}
}
}
查看全部 -
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
// 定義一個長度為5的字符串數(shù)組,保存考試科目信息
//數(shù)據(jù)類型[]?數(shù)組名 =?new?數(shù)據(jù)類型[數(shù)組長度];
String[] subjects = new String[5];?
//拆分:String[] subjects;
//? ? ? ? ? ?subjects = new String[5];
? ? ? ??
// 分別為數(shù)組中的元素賦值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";
? ? ? ??
System.out.println("數(shù)組中第4個科目為:" + subjects[3]);
}
}
查看全部 -
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? // 變量保存成績
? ? ? ? int score = 53;?
? ? ? ??
? ? ? ? // 變量保存加分次數(shù)
? ? ? ? int count = 0;
? ? ? ??
? ? ? ??
? ? ? ? //打印輸出加分前成績?
? ? ? ? System.out.println("加分前成績:" + score);??
? ? ? ?
? ? ? ??
? ? ? ? // 只要成績小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計加分次數(shù)
????? ? //使用while循環(huán)感覺簡單一些,也好理解
????? ? //當score小于60的時候,就+1,加完1再累計次數(shù),直到score不再小于60?? ?//
? ? ? ? while(score < 60) {
? ? ? ? ? ? score += 1;
? ? ? ? ? ? count ++;
? ? ? ? }
? ? ? ??
? ? ? ??
? ? ? ? //打印輸出加分后成績,以及加分次數(shù)
? ? ? ? System.out.println("加分后成績:" + score);
? ? ? ? System.out.println("共加了" + count + "次!");
? ? }
}
查看全部 -
定義類:public class
類名要首字母大寫(遵守變量定義規(guī)則):HelloWorld
程序的入口:public? static void main(String[] args){ }
調(diào)用類方法:String[] System.out.println()
語句結(jié)束符號:;(英文符號)
查看全部 -
漢化版,“打開于”-“在資源管理上顯示”即可
查看全部 -
String imooc ="慕課網(wǎng)";查看全部
-
public class Main {
? public static void main(String[] args) {
??? int age = 15;
??? if (age > 60) {
????? System.out.println("老年");
??? } else if (age > 40) {
????? System.out.println("中年");
??? } else if (age > 18) {
????? System.out.println("少年");
??? } else {
????? System.out.println("兒童");
??? }
???
? }
}
查看全部 -
自增和自減運算符只能用于操作變量,不能直接用于操作數(shù)值或常量!查看全部
-
%錯,標識符不能包含@%或空格查看全部
-
do...while 語句保證循環(huán)至少被執(zhí)行一次!查看全部
-
public class HelloWorld{
public static void main(String[] args){
int num = 999999;
int i=1;
int count;
//int count = 0;
for(i=1;i<=5;i++){
if(num/(Math.pow(10,i))<1){
? ? System.out.println("它是個"+i+"的數(shù)");
? ? count=i+1;
? ? break;
}
}
count=i+1;
if(count>6)
System.out.println("超過5位");
}? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
}
查看全部
舉報