我正在尝试代码一个基本的应用程序,它将获取用户想要输入的数字量,然后向用户询问数字,将数字保存在字符串数组中,然后以特定格式打印出来.
这是我到目前为止唯一的问题是我需要删除输出结束时的最后一个逗号,我确定我会发生这种错误......任何帮助都表示赞赏.
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(")");
}
}
Run Code Online (Sandbox Code Playgroud)
for(int l = 0;l<index.length;l++){
if(l==index.length-1)
System.out.printf("'%s'",index[l]);
else
System.out.printf("'%s',",index[l]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3227 次 |
| 最近记录: |