【发布时间】:2011-11-23 21:06:16
【问题描述】:
我正在尝试编写一个基本应用程序,该应用程序将获取用户想要输入的数字数量,然后向用户询问数字,将数字保存在字符串数组中,然后以特定格式打印出来。
这是我到目前为止唯一的问题是我需要删除输出末尾的最后一个逗号,我确定我做错了......感谢任何帮助。
import java.util.Scanner;
public class info {
public void blue(){
Scanner sc = new Scanner(System.in);
Scanner dc = new Scanner(System.in);
System.out.println("how many numbers do you have?");
int a = dc.nextInt();
System.out.println("enter your numbers");
String index[]=new String [a];
String i;
for(int k = 0;k<index.length;k++){
i = sc.nextLine();
index[k]=i;
}
System.out.print("query (");
for(int l = 0;l<index.length;l++){
System.out.printf("'%s',",index[l]);
}
System.out.print(")");
}
}
【问题讨论】:
-
您需要处理代码缩进。你可能会因为创造力而不是可读性而获得分数。