从标准输入(即键盘)读入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]);
}
}
}
请问哪里不对
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]);
}
}
}
解决方案 »
- 弱弱提问 《thinging in Java》的程序有点不明白?
- Junit 测试用例(NextDate)
- [求助] 关于JMF的问题
- 一个java类里面全是static方法,如何声明这个类的接口?
- java swing JFileChooser问题
- ----java中如何调用外部.dll-------
- 求助
- Error: Class jni could not be found.原因是什么?谢谢!
- 再贴WebLogic Server 和 Weblogic Integration 有何不同,各是用来做什么的?
- 如何得到控件的真实尺寸?
- 两个Panel如何交互数据?????????????????????????????
- 关于FOR循环
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]+" ");
}
}
}
可以用以下的代码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
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]+" ");
} }
}
{
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
如果要想得到整数则可以这样
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