달마루
기획자에서 개발자로
달마루
전체 방문자
오늘
어제
  • 분류 전체보기 (334)
    • 기획 이야기 (3)
    • 개발자로 전향한 이유 (1)
    • Github Address (1)
    • 개발자, 그 여정 (11)
      • 기초특강 (4)
      • 국비학원 선정 (4)
      • BitCamp_수업내용 (1)
      • 학원 프로젝트 후기 (1)
      • 정보처리기사 (1)
      • 개발 이야기 (0)
    • 개념 창고 (126)
      • JAVA (50)
      • CS (1)
      • Database (27)
      • NetWork (2)
      • 자료 구조 (2)
      • React (8)
      • Spring (3)
      • JPA (1)
      • HTML & CSS (18)
      • JS (3)
    • algorithm (186)
      • 백준 (161)
      • 프로그래머스 (23)
    • 사는 이야기 (0)

블로그 메뉴

  • Github
  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 알고리즘
  • Bronze IV
  • HTML
  • 백준알고리즘
  • Bronze III
  • 알고리즘풀이
  • SQL고득점Kit
  • 혼공SQL
  • 프로그래머스
  • 문제풀이
  • Scanner
  • 백준문제풀이
  • select
  • Bronze V
  • BOJ
  • 자바
  • react
  • 백준
  • java
  • MySQL
  • math
  • 혼공MySQL
  • programmers
  • BOJ algorithm
  • BRONZE
  • Algorithm
  • SQL
  • java algorithm
  • 혼자공부하는SQL
  • sql 문제풀이

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
달마루

기획자에서 개발자로

[백준] Lunacy - 4714 Java[자바]
algorithm/백준

[백준] Lunacy - 4714 Java[자바]

2023. 4. 9. 21:23


[Unrated] Lunacy - 4714

문제 링크

 

4714번: Lunacy

After several months struggling with a diet, Jack has become obsessed with the idea of weighing less. In an odd way, he finds it very comforting to think that, if he had simply had the luck to be born on a different planet, his weight could be considerably

www.acmicpc.net

성능 요약

메모리: 17880 KB, 시간: 220 ms

분류

수학, 구현, 사칙연산

문제 설명

After several months struggling with a diet, Jack has become obsessed with the idea of weighing less. In an odd way, he finds it very comforting to think that, if he had simply had the luck to be born on a different planet, his weight could be considerably less.

Of course, the planets are far out of reach, but even the Earth’s moon would yield a dramatic weight loss. Objects on the moon weight only 0.167 of their weight on Earth.

입력

Input consists of one or more lines, each containing a single floating point number denoting a weight (in pounds) on the Earth. The end of input is denoted by a negative floating point number.

출력

For each line of input data, your program should print a single line of the form

Objects weighing X on Earth will weigh Y on the moon.

where X is the weight from the input and Y is the corresponding weight on the moon. Both output numbers should be printed to a precision of 2 digits after the decimal point.



답 : 지구에서의 물체의 무게를 입력받아, 달에서의 무게로 변환하는 문제이다.
지구의 무게를 입력하다가 음수가 입력되면 입력을 종료한다.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double weightOnEarth = 0; // 지구에서의 무게를 저장할 변수
        while (true) { // 무한 반복문
            weightOnEarth = sc.nextDouble(); // 지구에서의 무게 입력받기
            if (weightOnEarth < 0) { // 입력이 음수이면 반복문 탈출
                break;
            }
            double weightOnMoon = weightOnEarth * 0.167; // 달에서의 무게 계산
            // 출력문, %.2f는 소수점 둘째자리까지 출력하도록 하는 포맷 문자열
            System.out.printf("Objects weighing %.2f on Earth will weigh %.2f on the moon.\n", weightOnEarth, weightOnMoon);
        }
        sc.close();
    }
}
저작자표시 비영리 변경금지 (새창열림)

'algorithm > 백준' 카테고리의 다른 글

[백준] 카드 뽑기 - 16204 Java[자바]  (0) 2023.04.11
[백준] 감소하는 수 -1038 Java[자바]  (0) 2023.04.09
[백준] 나부 함대 데이터 - 9654 Java[자바]  (0) 2023.04.01
[백준] 11021. A+B - 7 Java[자바]  (0) 2023.04.01
[백준] 큰 수 (BIG) - 14928 Java[자바]  (0) 2023.03.31
    'algorithm/백준' 카테고리의 다른 글
    • [백준] 카드 뽑기 - 16204 Java[자바]
    • [백준] 감소하는 수 -1038 Java[자바]
    • [백준] 나부 함대 데이터 - 9654 Java[자바]
    • [백준] 11021. A+B - 7 Java[자바]
    달마루
    달마루
    항상 어제보다 좋은 코드를 지향합니다. https://github.com/LimDongHyun99

    티스토리툴바