JAVA 프로그래밍

문제

사용자가 입력한 단어에서 어근과 접미사를 구분하는 문제입니다 실행순서를 클릭하세요 
-ly, -ment, -ance로 끝나는 단어를 입력하세요: lovely movement
lovely = love-ly
movement = move-ment 

프로그램 코드

	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		}
	}








 
실행 순서