📄 array03.java
字号:
// =============== Program Description ===============
// 程序名称: array03.java
// 程序目的: 运用一维数组设计一个可存储员工薪资,
// 让用户输入薪资,然后打印出员工编号的
// 程序。
// Written By Kuo-Yu Huang. (WANT Studio.)
// ===================================================
import ConsoleReader.*; // 引入已定义的数据输入类别
public class array03
{
// 预设10笔员工薪资数据
public static int[] Employee =
{ 27000, 32000, 32500, 27500, 28500,
29000, 31000, 32500, 30000, 26000 };
public static int Salary; // 用户输入薪资变量
public static int Counter = 0; // 数据计数变量
public static void main (String args[])
{
int i; // for循环计数变量
System.out.print("Please input the employee salary: ");
ConsoleReader console = new ConsoleReader(System.in);
// 读取欲查询薪资数据
Salary = console.readInt();
for (i=0;i<10;i++) // 数组查找循环
if (Salary == Employee[i]) // 当数据找到时
{
System.out.println("Number "+i+" Employee's salary is "+Salary+"!");
Counter++; // 数据计数变量加一
}
if (Counter == 0) // 当数据计数为零时
System.out.println("No employee's salary is "+Salary+" !!");
else // 当数据计数不为零时
System.out.println("Have "+Counter+" employees salary is "+Salary+" !!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -