从标准输入(即键盘)读入10个整数存入整型数组a中,然后逆序输出这10个整数。
请问哪里不对
public class Test3 {
     public static void main(String s[]){
        s=new String[10];
        for(int i=9;i>=0;i--){
            System.out.println(s[i]);
        }
     }
  
    
}

解决方案 »

  1.   

    楼主没有审题啊。“从标准输入(即键盘)读入10个整数存入整型数组a中”,你既没有从标准输出中读,又没有使用整形数组。只是定义了一个含有10个null元素的String数组。
      

  2.   

    你从键盘输入的时候只定义了一个含有10个null元素的String数组。可以用一个循环输出。public class Test3 {
         public static void main(String args[]){
    int[] s=new int[10];
    for(int i=0;i<s.length;i++)
     {
    s[i]=Integer.parseInt(args[i]);
    }

            for(int i=9;i>=0;i--){
                System.out.print(s[i]+" ");
            }
         }
      
        
    }
      

  3.   

    使用JDK1.5新加的一个类Scanner来从标准终端读入数据。
    可以用以下的代码import java.util.Scanner;public class Test3 {
         public static void main(String s[]){
    Scanner sc = new Scanner(System.in);
    int[] a = new int[10];
    int i; for(i = 0 ; i<10 ; i++)
    {
    a[i] = sc.nextInt();
    } for(i = 0 ; i<10 ; i++)
    {
    System.out.print(a[9-i]+" ");
    }
    System.out.println();
         }
    }执行过程:
    输入:0 1 2 3 4 5 6 7 8 9
    输出:9 8 7 6 5 4 3 2 1 0
      

  4.   

    import java.io.*;
    public class T {

    public static void main(String[] args) throws IOException{

    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    int[] i=new int[10];
    String s="";
    for(int j=0;j<10;j++){
    System.out.println("enter the "+(j+1)+" number:");
    s=bf.readLine();
    if(s!=null&&s.length()>0)
    i[j]=Integer.parseInt(s);
    }
    for(int j=9;j>=0;j--){
    System.out.print(i[j]+" ");
    } }
    }
      

  5.   

    public class ReadNum
    {
    public static void main(String args[])
    {
    String str[] = new String[10];
    for(int i=0;i<10;i++)
    {
    str[i] = args[i];
    }

    for(int i=9;i>=0;i--)
    {
    System.out.println(str[i]);
    }
    }
    }////////////////////
    运行时
    java ReadNum 10 9 8 7 6 5 4 3 2 1
      

  6.   

    以上代码得到是字符串
    如果要想得到整数则可以这样
    public class ReadNum
    {
    public static void main(String args[])
    {
    int i_a[] = new int[10];
    for(int i=0;i<10;i++)
    {
    i_a[i] = toInt(args[i]);
    }

    for(int i=9;i>=0;i--)
    {
    System.out.println(i_a[i]);
    }
    }
    public static int toInt(String str)
    {
    int i = Integer.parseInt(str);
    return i;
    }
    }////////////////////
    运行时
    java ReadNum 10 9 8 7 6 5 4 3 2 1
    输出 10 9 8 7 6 5 4 3 2 1