import java.util.Scanner;
public class Demo3
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter how many friends: ");
int numOfFriends = Integer.parseInt(scan.nextLine());
String arrayOfNames[] = new String[numOfFriends];
long income[] = new long[numOfFriends];
for (int i = 0; i < arrayOfNames.length; i++)
{
System.out.print("\nEnter the name of friend " + (i+1) + " : ");
arrayOfNames[i] = scan.nextLine();
for(int j = 0; j<arrayOfNames.length;j++)
{
System.out.print("\nEnter the income of friend " + (j+1) + " : ");
income[j] = scan.nextLong();
}
}
}
}
这是我的代码,我想从用户那里输入姓名然后是那个人的收入然后又是另一个人的名字上面的代码没有正确排列,我认为for循环有问题,示例输出应该是这样的:
Enter how many friends: 2
Enter name of friend 1 : #############
Enter income of friend 1 : ##############
Enter name of friend 2 : #############
Enter income of friend 2 : ##############
相关分类