U E D R , A S I H C RSS

자바민국/과제 (rev. 1.8)

자바민국/과제



1. 1회차

* 과제 : 맥주 99병 문제 풀기

1.1. 박인서

여기에 코드를 입력해주세요.

1.2. 송정우

여기에 코드를 입력해주세요.

1.3. 이승찬

여기에 코드를 입력해주세요.

1.4. 정우현

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int drink, drank, i;
        Scanner scanner = new Scanner(System.in);

        String input = scanner.nextLine();
        int number = Integer.parseInt( input ); 



        for(i = number; i > 1; i--){
            drink = i;
            drank = i-1;

            System.out.println(i + " bottles of beer on the wall, " + i + " bottles of beer.");

            if(drank > 1){
                System.out.println( "Take one down and pass it around, " + (i - 1) + " bottles of beer on the wall.");
            } else if(drank == 1){
                System.out.println( "Take one down and pass it around, " + (i - 1) + " bottle of beer on the wall.");
            }
            System.out.println();
        }

        System.out.println(i + " bottle of beer on the wall, " + i + " bottle of beer.");
        System.out.println("Take one down and pass it around, no more bottles of beer on the wall."); 
        System.out.println();

        System.out.println("No more bottles of beer on the wall, no more bottles of beer.");

        if(number > 1){
            System.out.println("Go to the store and buy some more, "+ number +" bottles of beer on the wall.");
        } else if (number == 1){
            System.out.println("Go to the store and buy some more, "+ number +" bottle of beer on the wall.");

        }
    }

}

1.5. 이호민

import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n;
        n=sc.nextInt();
        for(int i=n; i>0;){
            System.out.printf(i + " bottle" + (i==1?"":"s") + " of beer on the wall, " + i + " bottle" + (i--==1?"":"s") + " of beer.\n");
            if(i==0) System.out.printf("Take one down and pass it around, no more bottles of beer on the wall.\n\n");
            else System.out.printf("Take one down and pass it around, " + i + " bottle" + (i==1?"":"s") + " of beer on the wall.\n\n");
        }
        System.out.printf("No more bottles of beer on the wall, no more bottles of beer.\n" +
                "Go to the store and buy some more, " + n + " bottle" + (n==1?"":"s") + " of beer on the wall.");
    }
}

1.6. 김유현

import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int input;
        String l3;
		input = sc.nextInt();
        for(int i=input;i>0;i--){
            String l1,l2;
            l1=i+" bottles of beer";
            l2=i-1+" bottles of beer";
            if(i==2)
               l2="1 bottle of beer";
            else if(i==1){
                l1="1 bottle of beer";
                l2="no more bottles of beer";
            }
            System.out.println(l1+" on the wall, "+l1+".");
            System.out.println("Take one down and pass it around, "+l2+" on the wall.\n");
        }
        l3=input+" bottles of beer";
        if(input==1)
            l3="1 bottle of beer";
		System.out.println("No more bottles of beer on the wall, no more bottles of beer.");
	    System.out.println("Go to the store and buy some more, "+l3+" on the wall.");
    }
}

1.7. 좌민주

여기에 코드를 입력해주세요.

import java.util.Scanner;

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

        int num = scanner.nextInt();
        int beer = 0;
        
//노래 시작
        for ( beer = num ; beer > 0; beer--) {

           if (beer == 1) {
//맥주가 1개 남았을 때
                System.out.println( beer + " bottle of beer on the wall, " + beer +" bottle of beer." + "\n" +
                "Take one down and pass it around, no more bottles of beer on the wall.");
                System.out.println();
            } else {
//맥주가 1개이상 남았을 때
                if (beer == 2) {
                    System.out.println( beer + " bottles of beer on the wall, " + beer +" bottles of beer." + "\n" +
                    "Take one down and pass it around, " + (beer - 1) + " bottle of beer on the wall.");
                } else {
                     System.out.println( beer + " bottles of beer on the wall, " + beer +" bottles of beer." + "\n" +
                    "Take one down and pass it around, " + (beer - 1) + " bottles of beer on the wall.");
                }
                System.out.println();
            }
        }
//맥주가 없을 때
        if(num == 1){
           System.out.println( "No more bottles of beer on the wall, no more bottles of beer." + "\n" +
           "Go to the store and buy some more, " + num + " bottle of beer on the wall.");
        } else {
           System.out.println( "No more bottles of beer on the wall, no more bottles of beer." + "\n" +
           "Go to the store and buy some more, " + num + " bottles of beer on the wall.");
        }
          
    }
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-16 14:07:57
Processing time 0.0261 sec