不要自卑,去提升實力
互聯網行業誰技術牛誰是爹
如果文章可以帶給你能量,那是最好的事!請相信自己
加油o~

題目描述:
撰寫一個滿足下面要求的程式:
- 創建一個由100個隨機選取的整數構成的陣列
- 提示用戶輸入陣列的下標,然后顯示對應的元素值,如果指定的下標越界,則顯示訊息“Out of Bounds”
代碼:
/**
*作者:魏寶航
*2020年12月5日,上午8:09
*/
import java.util.*;
import java.util.concurrent.ExecutionException;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int[] arr=new int[100];
for(int i=0;i<100;i++) {
arr[i]=(int)(Math.random()*100);
}
System.out.println("請輸入陣列的下標:");
int n=sc.nextInt();
try {
if(n>=100||n<0) {
throw new Exception();
}
} catch (Exception e) {
System.out.println("Out of Bounds");
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/230700.html
標籤:其他
上一篇:DW層更新:HIVE腳本三步實作“緩慢變化維2更新”--保留歷史資料
下一篇:IDEA的瑞士軍刀~CSDN插件
