为什么会出现“ .class”预期错误?简单数组脚本 [英] Why am I getting a '.class' expected error? Simple Array script
本文介绍了为什么会出现“ .class”预期错误?简单数组脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序正在创建一个数组,并允许用户输入10个双精度数字。然后程序将按照从低到高的顺序对它们进行排序。我有以下内容,但在编译时收到.class预期错误。有什么想法为什么会这样?注意*我还不能编译它,所以我什至不知道这是否行得通。 *
My program is creating an array and allowing the user to input 10 double precision numbers. Then the program will sort them in order from lowest to highest. I have the following but receive .class expected error upon compiling. Any ideas on why this is happening? Note * I have not been able to compile this yet so I don't even know if this will work. *
import java.io.*;
public class ArrayDemo
{
public static void main(String[] args) throws IOException
{
int i = 0;
int j = 0;
int temp = 0;
double[] intValue = new double[10];
String[] numbers = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"};
int len = intValue.length[];
BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
for (i = 0; i < len; ++i)
System.out.println("Enter the " + numbers[i] + " number");
intValue[i] = Double.valueOf(dataIn.readLine());
{
for (j = 0; j < (len - 1) -i; j++)
if (intValue[j] > intValue[j+1])
{
temp = intValue[j];
intValue[j] = intValue[j+1];
intValue[j+1] = temp;
}
for (i = 0; i < 10; i++);
{
System.out.println("Array after sorting in ascending order");
System.out.println();
System.out.println(intValue[i]);
}
}
}
}
谢谢您的投入。 :)
推荐答案
int temp = 0;
应该为 double temp = 0;
和
int len = intValue.length [];
应该为 int len = intValue.length;
和
for(i = 0; i <10; i ++);
应该是表示(i = 0; i< 10; i ++)
EDIT
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException
{
int i = 0;
int j = 0;
int k = 0;
double temp = 0;
double[] intValue = new double[10];
String[] numbers = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"};
int len = intValue.length;
BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
for (i = 0; i < len; ++i) {
System.out.println("Enter the " + numbers[i] + " number");
intValue[i] = Double.valueOf(dataIn.readLine());
}
for (j = 0; j < len; j++)
{
for(k = 0; k < len; k++) {
if (intValue[j] > intValue[k])
{
temp = intValue[j];
intValue[j] = intValue[k];
intValue[k] = temp;
}
}
}
System.out.println("Array after sorting in ascending order");
for (i = 0; i < 10; i++)
{
System.out.print(intValue[i] + ", ");
}
}
}
这篇关于为什么会出现“ .class”预期错误?简单数组脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文