mojo's Blog

for-each 문 활용하기 본문

Java

for-each 문 활용하기

_mojo_ 2021. 7. 17. 22:00
import java.util.*;

public class Main {
	enum Week {월,화,수,목,금,토,일}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		
		int []n= {1,2,3,4,5};
		String []names= {"사과","배","바나나","체리","딸기","포도"};
		
		int sum=0;
		for(int k:n) {
			System.out.print(k+" ");
			sum+=k;
		}
		System.out.println("합은 "+sum);
		
		for(String s:names) {
			System.out.print(s+" ");
		}
		System.out.println();
		
		for(Week day:Week.values()) {
			System.out.print(day+"요일 ");
		}
		System.out.println();
		
		scanner.close();
	}

}

Comments