在java中使用scanner类将值插入两个数组
你应该把内环换成外环在java中使用scanner类将值插入两个数组,java,arrays,Java,Arrays,你应该把内环换成外环 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 : ############## import java.util.Scanner; 公开课演示3 { 公共静态void main(
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 : ##############
import java.util.Scanner;
公开课演示3
{
公共静态void main(字符串[]args)
{
扫描仪扫描=新扫描仪(System.in);
System.out.print(“输入有多少朋友:”);
int numofriends=Integer.parseInt(scan.nextLine());
字符串arrayOfNames[]=新字符串[numofriends];
长期收入[]=新的长期[numOfFriends];
for(int i=0;i 对于(int j=0;jI)我知道这是一个解决方案,但在这里我必须插入所有的名字,然后是他们的薪水,但我想先取第一个人的名字,然后是那个人的薪水,然后是第二个人的名字和他的薪水……就像这样。我不想使用arraylist。。
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 : ##############
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();
}
scan.close();
}
}
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();
System.out.print("\nEnter the income of friend " + (i+1) + " : ");
income[i] = scan.nextLong();
scan.nextLine();
}
scan.close();
}
}