【发布时间】:2014-06-07 20:24:05
【问题描述】:
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
String name = " ", n;
double r, h, s, m = 0;
int c;
Scanner i = new Scanner(System.in);
Employee e[] = new Employee[5];
for (int j = 0; j < 5; j++) {
System.out.printf("\nPlease enter the name of Employee %d ", j + 1);
/* THE PROBLEM LIES IN THE ABOVE STATEMENT IT IS EXECUTED ONLY ONCE WHILE IT'S MEANT TO BE EXECUTED 5 TIMES */
n = i.nextLine();
System.out.print("\t1.PartTime\n\t2.FullTime\n");
c = i.nextInt();
switch (c) {
case 1:
System.out.print("hours worked ");
h = i.nextDouble();
System.out.print("rate per hour ");
r = i.nextDouble();
e[j] = new Part(n, h, r);
break;
case 2:
System.out.print("Salary ");
s = i.nextDouble();
e[j] = new Full(n, s);
break;
default:
System.out.print("\n***INVALID*** ");
j--;
}
}
}
}
【问题讨论】:
-
只是好奇:您希望通过将句子全部大写来实现什么?
-
System.out默认刷新换行符。您的许多打印件可能没有冲洗。 -
@Braj 的休息是为 switch 语句
-
它按预期工作。分享实际代码。
-
Swing 是如何参与其中的?
标签: java loops for-loop java.util.scanner