2012-11-12 5 views
0

... for Java for 루프를 사용합니다. 예를 들어 hello는 다섯 번 인쇄됩니다. 우리는 스캐너 패키지를 사용할 필요가단어의 문자 수와 동일한 단어를 인쇄해야합니다.

import java.util.Scanner; 

class Words { 
public static void main(String[] args) { 
    Scanner scan = new Scanner(System.in); 
    System.out.println("Please enter one word of your choice"); 
    String word = scan.nextLine(); 
    System.out.println(word); 
    int length = word.length(); 
    System.out.println(length); 

    for (length < word; length++) { 
     System.out.println(word); 
    } 



} 
} 

:

여기에 지금까지 내 코드입니다. 죄송합니다. 이것이 정말 기본적인 것이지만 저는 방금 시작해서 어디에서나 답을 찾을 수 없습니다!

+1

문제는 무엇인가? –

+1

아마도 자신의 숙제를하는 것이 좋습니다. – Kylos

+0

'for (int n = word.length(); n> = 0; - n) {System.out.println (word); }' – oldrinb

답변

3

단어의 길이에 0을 실행하는 루프 만 작성하면됩니다. 아래 :

int length = word.length(); 
    for (int i = 0; i < length; i++) { 
    System.out.println(word); 
    } 
+0

이렇게했습니다! 도와 주셔서 감사합니다. –

+0

@MichaelDelahorne : 답변을 수락하는 것을 잊지 마십시오. –

0
for(int x = 0; x < word.length; x++){ 
    System.out.println(word); 
} 
1

전 C#의 프로그래밍을 할 수 있지만,이 비슷합니다. 이 같은 단지 사용자 뭔가 :이 도움이

string word = "hello"; 
int times = word.Length; 
for(int i = 0; i < times; i++) 
{ 
    System.out.println(word); // Java statment from your code 
} 

희망 ...

관련 문제