【发布时间】:2015-02-08 21:06:30
【问题描述】:
我正在尝试从整数转换为字符串以读取字符串中的数字序列。每次输入必须是一个字符串,而不是一个整数。将存储在 arraylist 中的数字不应是整数,而是字符串。
//wbin
//ow
int 计数 = 0; 整数 = 0;
最终 int SENTINEL = 0;
int 分数; `
int sum;
Scanner scan = new Scanner(System in);
ArrayList list = new Array();
System.out.println("Enter your digits");
System.out.println("Enter 0 to calculate");
score = scan.nextint();
while ( score !=SENTINEL)
{ total = score + total;
list.add(score);
count++;
System.out.println("next number");
score = scan.nextint();
}
if (count != 0)
{
DecimalFormat oneDecimalPlace = new DecimalFormat( "##.0" );
System.out.println("\nYour Average is "
+ oneDecimalPlace.format( (double) ( total / count) ) );
System.out.println("Your Total is " + total);
for (int i = list.size()-1; i >= 0; i--)
System.out.println(list.get(i));
}
else
System.out.println( "\nNo digits were entered" );
【问题讨论】:
-
请缩进你的代码并删掉与问题无关的代码。
标签: java arrays string arraylist integer