人事工號管理系統
阿新 • • 發佈:2022-05-05
人事工號管理系統
import java.util.Scanner; public class JobNumber { public static void main(String[] args) { int[] nums = new int[5]; int d = -1;//下標 Scanner scanner = new Scanner(System.in); while (true){ //功能選擇 System.out.println("請輸入選項: 1,新增工號;2,查詢工號;3,列印所有工號;4,退出"); int x = scanner.nextInt(); if (x == 4){ break; } if(x == 1){ System.out.println("請輸入需要新增工號!"); int nu = scanner.nextInt(); d++; //先判斷,不滿足條件先擴容 if (d > nums.length-1){ int[] temp = new int[nums.length*3]; for (int i = 0; i < nums.length ; i++) { temp[i] = nums[i]; nums = temp; } } nums[d] = nu; } if (x == 2){ System.out.println("請輸入需要查詢的工號"); int nu = scanner.nextInt(); int result = -1; for (int i = 0; i < nums.length; i++) { if (nu == nums[i]){ result = i; break; } } System.out.println(result == -1 ?"您輸入的工號不存在!":"該工號存在為:"+nums[result]); } if (x == 3){ for (int i = 0; i <= d ; i++) { System.out.println(nums[i]+" "); } } } } }