第一、二次实训作业
1.編寫程序:
??聲明一個整型變量a,并賦初值5,在程序中判斷a是奇數(shù)還是偶數(shù),然后輸出判斷的結(jié)果。
package 判斷奇偶;
public class liux {
? ?? public static void main(String[] args){
? ?? int x=5;
? ?? if(x%2==0){
? ?? System.out.println("這個數(shù)為偶數(shù)");
? ?? }else ?? System.out.println("這個數(shù)為奇數(shù)");
???? }
}
?
2.編寫程序:從鍵盤輸入圓的半徑,計算圓的面積并輸出。
package 計算圓的面積;import java.util.Scanner;
public class liux {
?static final double PI =? 3.14159; public static void main(String[] args){
??Scanner scanner=new Scanner(System.in);
??int r;
??System.out.println("請輸入圓的半徑:");
??r=scanner.nextInt();
??System.out.println("圓的面積為:"+PI*r*r);
??scanner.close();
?} }
?
3.編寫程序:實現(xiàn)一個數(shù)字加密器。運行時輸入加密前的整數(shù),通過加密運算后,輸出加密后的結(jié)果,加密結(jié)果仍為一整數(shù)。
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("請輸入加密前的數(shù)字:");
? ? x=scanner.nextInt();
? ? int n;
? ? n=(int) ((x*10+5)/2+3.1415926);
? ? System.out.println("加密后的數(shù)字為:"+n);
? ? scanner.close();
?}
}
?
4.聲明并創(chuàng)建存放4個人考試成績的一維數(shù)組,并使用for循環(huán)遍歷數(shù)組并打印分?jǐn)?shù)。要求:
- 首先按“順序”遍歷,即打印順序為:從第一個人到第四個人;
- 然后按“逆序”遍歷,即打印順序為:從從第四個人到第一個人;
- 輸出最高分;?
- 輸出最低分;
package 一維數(shù)組;
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+"個學(xué)生的成績?yōu)?#xff1a;"+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];
?} }
?
轉(zhuǎn)載于:https://www.cnblogs.com/liuxun1031/p/10695214.html
總結(jié)
- 上一篇: 列名 userid 不明确。 表结构_那
- 下一篇: 大数据采集技术和预处理技术