public static int number(String str){

String[] shuzu = str.split(" ");
int[] shuzuInt = new int[shuzu.length];
for(int i=0;i<shuzu.length;i++){
String shuzi = shuzu[i];
System.out.println(shuzi+" ");
int suzi = Integer.parseInt(shuzi); 
shuzuInt [i] = suzi;
}

return suzi;
}
public static void main(String[] agrements){
String haha = "12 15 18 -88 -99";
fuxi f1 = new fuxi();
String end = f1.number(haha);
System.out.println("看看:"+end);
}
}
这个我无法返回INT值  public static String number(String str){
String abc = str;
String[] shuzu = str.split(" ");
int[] shuzuInt = new int[shuzu.length];
for(int i=0;i<shuzu.length;i++){
String shuzi = shuzu[i];
System.out.println(shuzi+" ");
int suzi = Integer.parseInt(shuzi); 
shuzuInt [i] = suzi;
}

return abc;
}
public static void main(String[] agrements){
String haha = "12 15 18 -88 -99";
fuxi f1 = new fuxi();
String end = f1.number(haha);
System.out.println("看看:"+end);
}
}
但是用String我就能返回去 为什么INT不能啊 都是在FOR里循环 应该没问题啊
求解 谢谢各位了

解决方案 »

  1.   

    那相当于定义一个变量String str = 3;这样当然不行...
    int 转为String 用 3+""或者String.valueOf(3)
      

  2.   

    suzi在for里声明的,返回不了,你把suzi的声明放在for外试试
    abc是在for外声明的,可以返回,
      

  3.   

    这段代码好像编译不过。

    String shuzi = shuzu[i]; 
    System.out.println(shuzi+" "); 
    int suzi = Integer.parseInt(shuzi); 
    shuzuInt [i] = suzi; 
    } return suzi; 1.suzi 是局部变量,在循环的外面suzi的生命周期就结束了,编译不过的。
      

  4.   

    改成这样可以,不过打印看看的时候就只能看到-99了。public static int number(String str){
     String[] shuzu = str.split(" ");
     int[] shuzuInt = new int[shuzu.length];
     int suzi = 0;
     for(int i=0;i <shuzu.length;i++){
     String shuzi = shuzu[i];
     System.out.println(shuzi+" ");
     suzi = Integer.parseInt(shuzi);
     shuzuInt [i] = suzi;
     }
     return suzi;
     }


     public static void main(String[] agrements){
     String haha = "12 15 18 -88 -99";
     Test f1 = new Test();
     String end = String.valueOf(f1.number(haha));
     System.out.println("看看:"+end);
     }
      

  5.   

    public static int number(String str){ 
    int suzi=0;//*************
    String[] shuzu = str.split(" "); 
    int[] shuzuInt = new int[shuzu.length]; 
    for(int i=0;i <shuzu.length;i++){ 
    String shuzi = shuzu[i]; 
    System.out.println(shuzi+" "); 
    suzi = Integer.parseInt(shuzi); //******
    shuzuInt [i] = suzi; 
    } return suzi; 

    这样就可以了!原因是变量的定义位置错误!
      

  6.   

    变量的定义位置错误!for里定义的变量不能在for外面使用。
    public static int number(String str){ 
    int suzi=0;        //改为这里定义
    String[] shuzu = str.split(" "); 
    int[] shuzuInt = new int[shuzu.length]; 
    for(int i=0;i <shuzu.length;i++){ 
    String shuzi = shuzu[i]; 
    System.out.println(shuzi+" "); 
    suzi = Integer.parseInt(shuzi); 
    shuzuInt [i] = suzi; 

    return suzi; 
    }
      

  7.   

    还是作用域的问题..你suzi是声明在for 循环里面的,就是这样变量只在这一块作用域起作用
    想return suzi就把它拿到for外面去定义就好了.!
      

  8.   

    String end = f1.number(haha); 
    把end改成int类型就好了!
      

  9.   

    方法前边写int,return后边必须是兼容的类型.
      

  10.   

    用void定义方法时,无返回的,因为用void定义的方法
    如你说的这个就无返回的值
    public static void main(String[] agrements){ 
    String haha = "12 15 18 -88 -99"; 
    fuxi f1 = new fuxi(); 
    String end = f1.number(haha); 
    System.out.println("看看:"+end); 

      

  11.   

    package cn.itcast.testjava;public class TestReturnValue { /**
     * @param args
     */ static int[] number(String str){  String[] shuzu = str.split(" "); 
    int[] shuzuInt = new int[shuzu.length]; 
    for(int i=0;i <shuzu.length;i++){ 
    String shuzi = shuzu[i]; 
    System.out.println(shuzi+" "); 
    int suzi = Integer.parseInt(shuzi); 
    shuzuInt [i] = suzi; 
    }  return shuzuInt; 

    public static void main(String[] agrements){ 
    String haha = "12 15 18 -88 -99"; 

    int[] end = TestReturnValue.number(haha); 
    for(int i=0;i<end.length;i++) {
    System.out.println("看看:"+end[i]); 


    }
    }
    你这样试试看!!你把数字都存入一个INT[]数组里面,然后返回去!