1.編寫程序:
??聲明一個整型變量a,并賦初值5,在程序中判斷a是奇數還是偶數,然后輸出判斷的結果。
package 判斷奇偶;
public class liux {
? ?? public static void main(String[] args){
? ?? int x=5;
? ?? if(x%2==0){
? ?? System.out.println("這個數為偶數");
? ?? }else ?? System.out.println("這個數為奇數");
???? }
}
?
2.編寫程序:從鍵盤輸入圓的半徑,計算圓的面積并輸出。
import java.util.Scanner;
public class liux {
?static final double PI =? 3.14159;
??Scanner scanner=new Scanner(System.in);
??int r;
??System.out.println("請輸入圓的半徑:");
??r=scanner.nextInt();
??System.out.println("圓的面積為:"+PI*r*r);
??scanner.close();
?}

?
3.編寫程序:實現一個數字加密器。運行時輸入加密前的整數,通過加密運算后,輸出加密后的結果,加密結果仍為一整數。
package 加密器;
import java.util.Scanner;
public class liux {
? ? public static void main(String[] args) {
? ? Scanner scanner=new Scanner(System.in);
? ? int x;
? ? System.out.println("請輸入加密前的數字:");
? ? x=scanner.nextInt();
? ? int n;
? ? n=(int) ((x*10+5)/2+3.1415926);
? ? System.out.println("加密后的數字為:"+n);
? ? scanner.close();
?}
}
?
4.聲明并創建存放4個人考試成績的一維數組,并使用for循環遍歷數組并打印分數。要求:
- 首先按“順序”遍歷,即打印順序為:從第一個人到第四個人;
- 然后按“逆序”遍歷,即打印順序為:從從第四個人到第一個人;
- 輸出最高分;?
- 輸出最低分;
package 一維數組;
import java.util.Scanner;
public class liux {
?@SuppressWarnings("resource")
?public static void main(String[] args){
??int student[]=new int[5];
??int i;
??Scanner score=new Scanner(System.in);
??for(i=4;i>0;i--){
??student[i]=score.nextInt();
??System.out.println("第"+i+"個學生的成績為:"+student[i]);
??}?? int max=student[1];
??int min=student[1];
??for(i=1;i<5;i++){
???if(max<student[i])? ??max=student[i];
??}?? if(min>student[i]) ???min=student[i];
?} }
?