JAVA 프로그래밍

문제

사용자가 입력한 단어에서 어근과 접미사를 구분하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요 

프로그램의 실행순서 및 실행상태

1  public static void main( String[] args ) {    

2   String input = scan.nextLine();
-ly, -ment, -ance로 끝나는 단어를 입력하세요: lovely movement
                   main()
   input
                                               

3   String[] words = input.split( " " );

4   for( String word : words ) {

lovely = 

5    for( String suffix : suffixes )

6     root = root.replace( suffix, "" );
                   main()
   input  lovely movement 
            [0]       [1]       [2]   
suffixes     ly       ment     ance 
   words
    word
    root
  suffix
                                               

5    for( String suffix : suffixes )

6     root = root.replace( suffix, "" );
                   main()
   input  lovely movement 
            [0]       [1]       [2]   
suffixes     ly       ment     ance 
   words   lovely    movement 
    word      lovely     
    root
  suffix
                                               

5    for( String suffix : suffixes )

6     root = root.replace( suffix, "" );
                   main()
   input  lovely movement 
            [0]       [1]       [2]   
suffixes     ly       ment     ance 
   words   lovely    movement 
    word      lovely     
    root
  suffix
                                               

5    for( String suffix : suffixes )

love

7    for( String suffix : suffixes ) {

8     if ( word.contains( suffix ) ) {

9      int index = word.indexOf( suffix );

10      System.out.println( "-" + word.substring( index ) );
-ly
                   main()
   input  lovely movement 
            [0]       [1]       [2]   
suffixes     ly       ment     ance 
   words   lovely    movement 
    word
    root
  suffix
   index
                                               

11      break;

4   for( String word : words ) {

movement = 

5    for( String suffix : suffixes )
                                              
... 

5    for( String suffix : suffixes )

move

7    for( String suffix : suffixes ) {

8     if ( word.contains( suffix ) ) {

7    for( String suffix : suffixes ) {

8     if ( word.contains( suffix ) ) {

9      int index = word.indexOf( suffix );

10      System.out.println( "-" + word.substring( index ) );
-ment
                   main()
   input  lovely movement 
            [0]       [1]       [2]   
suffixes     ly       ment     ance 
   words   lovely    movement 
    word
    root
  suffix
   index
                                               

11      break;

4   for( String word : words ) {

12  }


프로그램 코드

	import java.util.Scanner;
		
	public class Suffix
	{
1		public static void main( String[] args ) { 			
			Scanner scan = new Scanner( System.in );
	
			System.out.print( "-ly, -ment, -ance로 끝나는 단어를 입력하세요: " );
2			String input = scan.nextLine();
	
			String[] suffixes = { "ly", "ment", "ance" };
3			String[] words = input.split( " " );
4			for( String word : words ) {
				System.out.print( word + " = " );
	
				String root = word;
5				for( String suffix : suffixes )
6					root = root.replace( suffix, "" );
				System.out.print( root );
				
7				for( String suffix : suffixes ) {
8					if ( word.contains( suffix ) ) {
9						int index = word.indexOf( suffix );
10						System.out.println( "-" + word.substring( index ) );
11						break;
					}
				}
			}
	
			scan.close();
12		}
	}