人数と合計金額を入力すると100円単位での割り勘金額を出力する。
人数と合計金額を入力してください
7 10000
一人あたりの金額は、1428.5714285714287円です。
100円単位では、一人当たり1400円、ひとりだけ1600円です。
Calc.java
import java.util.Scanner;
class Calc{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("人数と合計金額を入力してください");
int i,j,l,n;
i = scan.nextInt();
j = scan.nextInt();
double f,g;
f = (double)j/i;
System.out.println("一人あたりの金額は、" + f + "円です。");
l = (int)Math.round(f/100)*100;
n = j-l*(i-1);
System.out.println("100円単位では、一人当たり" + l + "円、ひとりだけ" + n + "円です。");
}
}
new Scanner(System.in)
とかscan.nextInt()
とかMath.round
とか理解はあまいがとりあえず進もう。