日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

第一、二次实训作业

發布時間:2023/12/10 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第一、二次实训作业 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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.編寫程序:從鍵盤輸入圓的半徑,計算圓的面積并輸出。

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.編寫程序:實現一個數字加密器。運行時輸入加密前的整數,通過加密運算后,輸出加密后的結果,加密結果仍為一整數。

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];
?} }

?

轉載于:https://www.cnblogs.com/liuxun1031/p/10695214.html

總結

以上是生活随笔為你收集整理的第一、二次实训作业的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。