목록Java (58)
mojo's Blog
0으로 나눌 때 발생하는 ArithmeticException 예외 처리 code import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); while(true) { System.out.print("나뉨수를 입력하세요: "); int dividend=scanner.nextInt(); System.out.print("나눗수를 입력하세요: "); int divisor=scanner.nextInt(); try { System.out.println(dividend/divisor); break; }..
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+" "); } Syst..