将一维数组按逆序输出
用BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
str[i]= Integer.parseInt(input.readLine());这个
将一维数组按逆序输出
用BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
str[i]= Integer.parseInt(input.readLine());这个
import java.io.*;
public class Test1
{
public static void main(String[] args) throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
int[] str = null;
System.out.println("请输入数组长度:");
int length = Integer.parseInt(input.readLine());
str = new int[length];
System.out.println("输入数组元素:");
for(int i = 0; i < length;i++ )
str[i]= Integer.parseInt(input.readLine());
System.out.println("逆序输出:");
for(int i = length - 1; i >= 0;i--)
System.out.print(str[i] + " ");
}
}
input.readLine()是一行数据,包含回车换行,trim一下就行了
str[i]= Integer.parseInt(input.readLine().trim());