配列内の2つの特定の要素を変換する方法についてネット全体を検索しましたが、その研究については非常に不運でした
package scanner;
import java.util.Scanner;
public class EmployeeInformation {
static Scanner sc = new Scanner(System.in);
static String[][] info = {{"09-001", "Ja Gb", "100", "10", },
{"09-002", "Justine", "200", "20", },
{"09-003", "Ja Ja", "150", "15", }};
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print(" - MENU -\n");
System.out.print("A. Search Record\nB. Payroll Summary\n------------------\nEnter choice: ");
String choice = null;
choice = sc.nextLine();
if (choice.equalsIgnoreCase("a")) {
System.out.print("Enter Employee #: ");
String EmpNum = sc.nextLine();
SearchRecord(EmpNum);
}
else if (choice.equalsIgnoreCase("b")){
PayrollSummary();
}
else {
System.out.print("Invalid input.");
}
}
private static void SearchRecord(String employeeNumber) {
// TODO Auto-generated method stub
String[] matchedRow = null;
for (int i = 0; i < info.length; i++) {
String[] oneRow = info[i];
if (oneRow[0].equals(employeeNumber)) {
matchedRow = oneRow;
break;
}
}
System.out.print("\nEmployee #:\tEmployee Name\tRate per Hour\tTotal Hours Worked\n");
for (int i = 0; i < matchedRow.length; i++) {
System.out.print(matchedRow[i] + "\t\t");
}
}
private static void PayrollSummary() {
System.out.println("\nEmployee #:\tEmployee Name\tRate per Hour\tTotal Hours Worked\tGross Pay");
int intArr[] = new int[info.length];
int r = 0;
while ( r < info.length) {
int c = 0;
while ( c <= r ) {
if ( c == 2 ) {
intArr[c] = Integer.parseInt(info[r][c]);
if ( c == 3 ) {
intArr[c] = Integer.parseInt(info[r][c]);
}
}
c++;
// How do I multiply index 2 and 3 of Array info and store it in info[r][4]?
}
r++;
}
}
}
...