Java/JetBrain Project

JetBrain [Easy] Simply Chatty Bot 만들기 - Stage 4

aliceintr 2020. 12. 2. 09:32
반응형

오늘은 네번째 스테이지,

설명을 읽어보자

 

유저가 특정값을 입력하면 카운트 다운을 할 수 있게 하는 기능을 만드는 것이다.

예를들어

유저가 7을 눌렀으면

0부터 시작해서 7까지 카운트를 세주면 된다.

 

for 문을 이용해서 코드를 짜주었다.

package bot;
import java.util.Scanner;

    public class Chatbot {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            System.out.println("Hello! My name is Aid.");
            System.out.println("I was created in 2018.");
            System.out.println("Please, remind me your name.");

            String name = scanner.nextLine();

            System.out.println("What a great name you have, " + name + "!");
            System.out.println("Let me guess your age.");
            System.out.println("Enter remainders of dividing your age by 3, 5 and 7.");

            int rem3 = scanner.nextInt();
            int rem5 = scanner.nextInt();
            int rem7 = scanner.nextInt();

            int age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105;

            System.out.println("Your age is " + age + "; that's a good time to start programming!");
            System.out.println("Now I will prove to you that I can count to any number you want.");

            // read a number and count to it here
            int count = scanner.nextInt();
            for (int i = 0; i <=count ; i++){
                System.out.println(i+"!");
            }

            System.out.println("Completed, have a nice day!");


        }
    }
반응형