简体   繁体   English

当我在jgrasp中运行此代码时,没有输出,并且代码没有结束

[英]When I run this code in jgrasp there is no output and the code doesn't end

import java.util.Scanner;

class Lesson_30_Activity {

    public static String [] list = {"every", " near  ing ", "      checking", "food ", "stand", "value      "};

public static void main(String[] args)
 {
 String s=null;
 for(int i =0;i<list.length;i++){

 for(int j =0;j<list[i].length();j++){

 if(list[i].charAt(j)!=' '){
  s =s+list[i].charAt(j);


 }

 list[i]=list[i]+s;     
 }

 s=null;
 System.out.println(list[i]); 

 }
 }
}

I think that either the for loop I'am using isn't stopping and one of them isn't stopping or the varibale s isn't being added to the position in the list[i]. 我认为我正在使用的for循环没有停止并且其中一个没有停止或者varibale s没有添加到列表中的位置。

问题在于,内部循环可以使迭代的字符串更长。

When you run into a situation like this, to see what is going on either use the debugger and step through the code or add print statements. 当您遇到这种情况时,请使用调试器并逐步执行代码或添加打印语句,以查看发生的情况。

For example, after: 例如,之后:

list[i]=list[i]+s;

add

System.out.println("i " + i + " j " + j + " list[i] " + list[i]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM