JAVA예제2010. 9. 13. 11:18
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: moonleaf
 * Date: 2010. 9. 13
 * Time: 오전 10:56:21
 * To change this template use File | Settings | File Templates.
 */
public class ConsoleEx01 {
    public static void main(String[] args) {
        while(true) {
            String prompt = ">>";
            System.out.print(prompt);

            Scanner in = new Scanner(System.in);

            String console = in.nextLine();

            if(console.equals("q") || console.equals("Q")){
                break;
            }
                  /*

                     다음과 같은 내용의 코드를 넣으세요.

                     1. 화면으로부터 라인단위로 입력받는다.  - java.util.Scanner클래스 사용
                     2. q 또는 Q를 입력하면 실행종료한다.

                  */


             } // while(true)
      } // main

}


'JAVA예제' 카테고리의 다른 글

JAVA 예제 3-2  (0) 2010.09.13
JAVA 예제 2-3  (0) 2010.09.13
JAVA 예제 2-2  (0) 2010.09.13
JAVA 예제 2-1  (0) 2010.09.10
JAVA 예제 1-4  (0) 2010.09.10
Posted by 달빛낙엽
JAVA예제2010. 9. 13. 10:54
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: moonleaf
 * Date: 2010. 9. 13
 * Time: 오전 10:30:30
 * To change this template use File | Settings | File Templates.
 */
public class Ex007 {
    public static void main(String[] args) {
        String[] data = {
                         "다음 중 키워드가 아닌 것은?`2`final`True`if`public",
                         "다음 중 자바의 연산자가 아닌 것은?`6`&`|`++`!=`/`^",
                         "다음 중 메서드의 반환값이 없음을 의미하는 키워드는?`1`void`null`false`",
                         };

        Scanner s = new Scanner(System.in);
        int score = 0;

        shuffle(data); // 문제를 섞는다.

        for(int i=0;i < data.length;i++) {
            String[] tmp = data[i].split("`",3);

            String question = tmp[0];
            String answer = tmp[1];
            String[] choices = tmp[2].split("`");

            answer = choices[Integer.parseInt(answer)-1];

            shuffle(choices); // 선택지를 섞는다.

            System.out.println("["+(i+1)+"] "+question);

            for(int x=0;x < choices.length;x++) {
                System.out.print(x+1 +". " +choices[x]);
                System.out.print("    ");

                      /*

                               코드를 완성하세요.

                      */
            }

            System.out.println();
            System.out.print("[답]");
            String input = s.nextLine();
            input = choices[Integer.parseInt(input) -1];

            System.out.println(input);
            System.out.println(answer);
            if(input.equals(answer)) {
               score++;
            }

            System.out.println();
            System.out.println();
        }

        System.out.println("정답개수/전체문항수 :"+score+"/"+data.length);
    } // main

      public static void shuffle(String[] data) {
          String tmp = "";

          if(data.length == 0){
              System.out.println("정지");
          }else{
             for(int i = 0; i <data.length *2;i++){
                 int y = (int)(Math.random()*data.length);
                 tmp = data[0];
                 data[0] = data[y] ;
                 data[y] = tmp;
             }
          }
           // 코드를 완성하세요.

           //  1. 배열data의 개수가 0보다 같거나 적으면 메서드 전체를 빠져나간다.

           //  2. 선택지의 순서를 뒤바꾼다. 반복문과 Math.random()사용
      } // shuffle()

}


'JAVA예제' 카테고리의 다른 글

JAVA 예제 3-2  (0) 2010.09.13
JAVA 예제 3-1  (0) 2010.09.13
JAVA 예제 2-2  (0) 2010.09.13
JAVA 예제 2-1  (0) 2010.09.10
JAVA 예제 1-4  (0) 2010.09.10
Posted by 달빛낙엽
JAVA예제2010. 9. 13. 10:27
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: moonleaf
 * Date: 2010. 9. 13
 * Time: 오전 9:25:13
 * To change this template use File | Settings | File Templates.
 */
public class Ex006 {
    public static void main(String[] args) {
        String[] data = {
                         "다음 중 키워드가 아닌 것은?`2`final`True`if`public",
                         "다음 중 자바의 연산자가 아닌 것은?`6`&`|`++`!=`/`^",
                         "다음 중 메서드의 반환값이 없음을 의미하는 키워드는?`1`void`null`false`",
                         };

        Scanner s = new Scanner(System.in);
        int score = 0;

        for(int i=0;i < data.length;i++) {
              String[] tmp = data[i].split("`",3);

              String question = tmp[0];
              String answer = tmp[1];
              String[] choices = tmp[2].split("`");

              System.out.println("["+(i+1)+"] "+question);

              for(int x=0;x < choices.length;x++) {
                    System.out.print((x+1)+"."+choices[x]+"\t");
              }
           
              System.out.println();

              System.out.print("[답]");
              String input = s.nextLine();
              if(input.equals(answer)){
                  score = score +1;
              }

              System.out.println();
              System.out.println();
        }


        System.out.print("정답개수/전체문항수 : "+ score + "/" + data.length );

    } // main

}


'JAVA예제' 카테고리의 다른 글

JAVA 예제 3-1  (0) 2010.09.13
JAVA 예제 2-3  (0) 2010.09.13
JAVA 예제 2-1  (0) 2010.09.10
JAVA 예제 1-4  (0) 2010.09.10
JAVA 예제 1-3  (0) 2010.09.10
Posted by 달빛낙엽