import java.util.Scanner;
public class cs {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
String s[]=new String[10];
double d[]=new double[5];
for(int j=0;j<3;j++)
{
System.out.print("输入购买的物品:");
s[j]=in.nextLine();
System.out.print("输入物品的单价:");
d[j]=in.nextDouble();
}
}
}
------解决方案--------------------
换成下面这样正常了
- Java code
import java.util.Scanner;public class Cs { public static void main(String[] args) {// TODO Auto-generated method stub String s[]=new String[10]; double d[]=new double[5]; for(int j=0;j<3;j++) { Scanner in=new Scanner(System.in); System.out.print("输入购买的物品:"); s[j]=in.nextLine(); System.out.print("输入物品的单价:"); d[j]=in.nextDouble(); } }}
------解决方案--------------------
你这写就没有问题!
import java.util.Scanner;
public class cs {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String s[] = new String[10];
double d[] = new double[5];
for (int j = 0; j < 3; j++) {
System.out.println("输入购买的物品:");
s[j] = in.nextLine();
System.out.println("输入物品的单价:");
d[j] = in.nextDouble();
}
}
}
------解决方案--------------------
- Java code
import java.util.Scanner;public class cs { public static void main(String args[]) { for ( int i=0 ; i<3 ; i++ ) { Scanner in = new Scanner(System.in); String s [] = new String [10]; double d [] = new double [5]; System.out.println("输入购买的物品:"); s[i] = in.nextLine(); System.out.println("输入物品的单价:"); d[i] = in.nextDouble(); }}}