gpt4 book ai didi

java - 为什么我会收到 '.class' 预期错误?简单数组脚本

转载 作者:行者123 更新时间:2023-12-01 05:39:24 28 4
gpt4 key购买 nike

我的程序正在创建一个数组并允许用户输入 10 个 double 字。然后程序将按照从低到高的顺序对它们进行排序。我有以下内容,但在编译时收到 .class 预期错误。关于为什么会发生这种情况有什么想法吗?注意*我还无法编译它,所以我什至不知道这是否有效。 *

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++);应该是for (i = 0; i < 10; i++)

Sample

<小时/>

编辑

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] + ", ");

}

}
}

关于java - 为什么我会收到 '.class' 预期错误?简单数组脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7535073/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com