第一关关键字
package step1;
public class KeyWord {public static void main(String[] args) {System.out.println("Hello world!");}
}
第二关
标示符
package step2;public class Identifier {public static void main(String[] args) {/********* Begin *********/String s = "java实训";int i =2;System.out.println(s + i);/********* End *********/}
}
第三关ifelse分支
package step3;import java.util.Scanner;public class ifelse {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int grade = scanner.nextInt();if(grade>=0&&grade<=59){System.out.print("不及格");}else if(grade>=60&&grade<=75)System.out.print("良好");else if(grade>=76&&grade<=85)System.out.print("优秀");else if(grade>=86&&grade<=100)System.out.print("非常优秀");elseSystem.out.print(" 你输入的成绩有误!");// ---------------------Begin------------------------//0-59 -> 不及格//60-75 -> 良好//76-85 -> 优秀//86-100 -> 非常优秀// ---------------------End------------------------}}
第四关swich
package step4;import java.util.Scanner;public class SwitchCase {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int month = scanner.nextInt();switch(month){case 12: case 1: case 2:System.out.print("当前为时间为冬季");break;case 3: case 4: case 5:System.out.print("当前时间为春季");break;case 6: case 7: case 8:System.out.print("当前时间为夏季");break;case 9: case 10: case 11:System.out.print("当前时间为秋季");break;default:System.out.print("输入的月份不正确!!!");break;}// ---------------------Begin------------------------//季节划分[12,1,2]=冬季.[3,4,5]= 春季, [6,7,8]=夏季,[9,10,11]= 秋季// ---------------------End------------------------}
}
第五关三元运算符
ackage step5;import java.util.Scanner;public class Threeyuan {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int a = scanner.nextInt();int b = scanner.nextInt();// ---------------------Begin------------------------//将???的位置替换成3元表达式,要求a>=b时maxvalue=a,否则maxvalue=bint maxvalue = a>=b?a:b;// ---------------------End------------------------System.out.println("两数中的最大值为:"+maxvalue);}
}
第六关while循环
package step6;import java.util.Scanner;public class WhileCircle {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int a = scanner.nextInt();int i=0;while(i<=a){System.out.println(i);i++;}// ---------------------Begin------------------------//使用while循环输出0-a的所有整数// ---------------------End------------------------}
}
第七关for循环
package step7;import java.util.Scanner;public class ForCircle {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int row = scanner.nextInt();// ---------------------Begin------------------------for(int i=1;i<=row;i++){for(int j=1;j<=i;j++){System.out.print("*");}System.out.println();}// ---------------------End------------------------}
}