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里循环 应该没问题啊
求解 谢谢各位了
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里循环 应该没问题啊
求解 谢谢各位了
int 转为String 用 3+""或者String.valueOf(3)
abc是在for外声明的,可以返回,
{
String shuzi = shuzu[i];
System.out.println(shuzi+" ");
int suzi = Integer.parseInt(shuzi);
shuzuInt [i] = suzi;
} return suzi; 1.suzi 是局部变量,在循环的外面suzi的生命周期就结束了,编译不过的。
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);
}
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;
}
这样就可以了!原因是变量的定义位置错误!
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;
}
想return suzi就把它拿到for外面去定义就好了.!
把end改成int类型就好了!
如你说的这个就无返回的值
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);
}
}
* @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[]数组里面,然后返回去!