본문 바로가기

프로그래밍/자바의정석_4_연습문제15

[4-7] Math.random()을 이용해서 1부터 6사이의 임의의 정수를 변수 value에 저장하는 코드를 완성하라. (1)에 알맞은 코드를 넣으시오. public class ex_007 { // [4-7] Math.random()을 이용해서 1부터 6사이의 임의의 정수를 변수 value에 저장하는 코드를 완성하라. (1)에 알맞은 코드를 넣으시오. // [연습문제]/ch4/Exercise4_7.java // class Exercise4_7 { // public static void main(String[] args) { // int value = (1); // System.out.println("value:"+value); // } // } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int value = (int) (Mat.. 2014. 8. 5.
[4-6] 두 개의 주사위를 던졌을 때, 눈의 합이 6이 되는 모든 경우의 수를 출력하는 프로그램을 작성하시오. public class ex_006 { // [4-6] 두 개의 주사위를 던졌을 때, 눈의 합이 6이 되는 모든 경우의 수를 출력하는 프로그램을 작성하시오. /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int sum = 0; for (int i = 1; i 2014. 8. 5.
[4-5] 다음의 for문을 while문으로 변경하시오. public class ex_005 { // [4-5] 다음의 for문을 while문으로 변경하시오. // [연습문제]/ch4/Exercise4_5.java // public class Exercise4_5 { // public static void main(String[] args) { // for(int i=0; i 2014. 8. 5.
[4-4] 1+(-2)+3+(-4)+.. 과 같은 식으로 계속 더해나갔을 때, 몇까지 더해야 총합이 100이상이 되는지 구하시오. /** * @author Administrator * @문제 [4-4] 1+(-2)+3+(-4)+.. 과 같은 식으로 계속 더해나갔을 때, 몇까지 더해야 총합이 100이상이 되는지 구하시오. */ public class ex_004 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // Ex01(); Ex01(); Ex02(); } static void Ex01() { // 홀수면은 + 짝수면은 - int num = 0; int count = 0; int i = 0; while (num < 100) { count++; i++; if (i % 2 == 0) { num = num +.. 2014. 7. 24.