Last active
August 29, 2015 14:01
-
-
Save HabaCo/9860fdcb2193ff824feb to your computer and use it in GitHub Desktop.
class-prac-main.java
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
| public class CalMain { | |
| public static void main(String[] args) { | |
| CalPlus c1 = new CalPlus(2,4,83,240); | |
| System.out.println(c1.counta+"隻"+c1.countb+"隻"); | |
| CalPlus c2 = new CalPlus(12,15,24,312); | |
| System.out.println("麵包"+c2.counta+"個"+c2.countb+"個"); | |
| } | |
| } |
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
| public class CalPlus { | |
| private int basea; // 基數a | |
| private int baseb; // 基數b | |
| private int aplusb; // a+b | |
| private int calabsum; // ax+by | |
| public int counta; // 計算結果 a | |
| public int countb; // 計算結果 b | |
| public CalPlus(int a, int b, int c, int d) { | |
| basea = a; | |
| baseb = b; | |
| aplusb = c; | |
| calabsum = d; | |
| cNum(); | |
| } | |
| public void cNum() { | |
| stop: | |
| for (int i = 1; i <= aplusb; i++) | |
| for (int j = 1; j <= aplusb; j++) | |
| if (basea * i + baseb * j == calabsum && i + j == aplusb) { | |
| counta = i; // i 存入 counta | |
| countb = j; // j 存入 countb | |
| break stop; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment