식물이 자라는 방식을 시뮬레이션하기 위해이 아이디어를 생각해 냈습니다. 아이디어는 프랙탈 기하학을 기반으로하며 기본적으로 식물의 가지 및 기타 구조물의 반복을 설명합니다. 나는 프로그래밍에 초보자이기 때문에 뭔가를 반복하는 기본 논리 만 테스트해볼 것이라고 생각했다. 아래는 자바에서 쓴 것입니다.Java - 중첩 루프 - 출력을 얻는 데 문제가 있음
- 내 자바 보관소에 저장된
MacBook-Air:Java bdeely$ javac plant.java
- 로/컴파일 된 코드 호출이
- 를 가리 키도록 내 예탁을 변경
MacBook-Air:Java bdeely$ java plant
으로 코드를 실행 :
나는 다음을했다/* Java program: plant.java This program runs a loop simulating plant growth. The idea is that the plant will continue to have "repeated" growth and that it will stop (or slow down to a crawl) at some point, in this case at 100 branches. */ public class plant { public static void main (String [] poop) { int current_growth = 0, limit = 100; //plant growth starts at ZERO and is limited to 100 String word = "branches"; while (current_growth > 0) { //here, we are checking to see if the plant has grown just 1 inch. //this is important just for grammatical purposes if (current_growth == 1) { word = "branch"; //this changes the "word" to branch instead of branches } System.out.println("Your plant has grown " + current_growth + " " + word); //if you put the singular count check here, it doesn't work at all current_growth = current_growth + 1; if (current_growth > 0) { System.out.println("Your plant has grown " + current_growth + " " + word); } else { System.out.println("Your plant will no longer grow."); } // end else } //end while loop } //end main method } //end class
문제는 다음과 같습니다. - 출력이 전혀 없습니다. 명령 프롬프트가 비어있는 것처럼 돌아왔다. MacBook-Air:Java bdeely$
나는 거대한 루키 실수를하고있다. 아무도 내가이 코드를 얻을 수있는 줄 내게 0에서 최대 100 루프를 반복 할 줄 알아요?
감사합니다. current_growth
이후
'while'루프 상태를 확인하십시오. 그것은 진실이 아니므로, 집행은 그것에 들어 가지 않습니다. –