Created
December 8, 2014 11:14
-
-
Save d-kanazawa/f7bac2199a4d8b0c34b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* プログラム名 Ryogae2.java | |
* プログラムの内容の説明 日本円(¥)を入力し,その金額を米ドル(US$)に両替するプログラム | |
* 作成日 12/8 | |
*/ | |
public class Ryogae2 { | |
public static void main(String[] args) { | |
String line =System.console().readLine("金額(日本円)="); | |
int n =Integer.parseInt(line); | |
int o = n - ((n/117)*117); | |
int s; //紙幣 | |
if(n < 117){ | |
System.out.println("両替できません"); | |
}else{ | |
n = n / 117; //円をドルに変換 | |
System.out.println("両替できる日本円は" + (n * 117) + "円でドルに変換すると" + n +"ドルです。"); | |
s = n / 100; //100ドル札を求める | |
n = n % 100; //100ドルで割ったお釣り | |
if(s != 0){ | |
System.out.println("100ドル札が"+ s +"枚です。"); | |
} | |
s = n / 50; //50ドル札を求める | |
n = n % 50; //50ドルで割ったあまり | |
if(s != 0){ | |
System.out.println("50ドル札が"+ s +"枚です。"); | |
} | |
s = n / 20; //20ドル札を求める | |
n = n % 20; //20ドル札で割ったあまり | |
if(s != 0){ | |
System.out.println("20ドル札が"+ s +"枚です。"); | |
} | |
s = n / 10; //10ドル札を求める | |
n = n % 10; //10ドル札で割ったあまり | |
if(s != 0){ | |
System.out.println("10ドル札が"+ s +"枚です。"); | |
} | |
s = n / 5; //5ドルを求める | |
n = n % 5; //5ドルで割ったあまり | |
if(s != 0){ | |
System.out.println("5ドル札が" + s + "枚です。"); | |
} | |
if(n != 0){ | |
System.out.println("1ドル札が" + n +"枚です。"); | |
} | |
if(o != 0){ | |
System.out.println("お釣りは" + o + "円です。"); | |
} else { | |
System.out.println("お釣りはありません。"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment