Created
May 20, 2014 01:53
-
-
Save siritori/2e8f000c4b4d93f06d14 to your computer and use it in GitHub Desktop.
情報科学I
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 ArgsCheck | |
{ | |
public static void main(String args[]) { | |
if(args.length != 1) { | |
System.err.println("Wrong arguments"); | |
return; | |
} | |
int number = Integer.parseInt(args[0]); | |
if(check(number)) { | |
System.out.println(number + " is OK!"); | |
} else { | |
System.out.println(number + " is NG!"); | |
} | |
} | |
static boolean check(int n) { | |
return n >= 100 && n <= 60000; | |
} | |
} |
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 Saving | |
{ | |
public static void main(String args[]) { | |
if(args.length != 3) { | |
System.err.println("Wrong arguments"); | |
return; | |
} | |
long principal = Long.parseLong(args[0]); // 元金 | |
double interestRate = Double.parseDouble(args[1]); // 金利率 | |
int term = Integer.parseInt(args[2]); // 借用期間 | |
int nowSaving = (int)calculate(principal, 1.0 + interestRate, term); | |
System.out.println("Principal : " + principal); | |
System.out.println("Interest rate : " + interestRate); | |
System.out.println("Term : " + term); | |
System.out.println("Now Saving : " + nowSaving); | |
} | |
static double calculate(long principal, double interestRate, int term) { | |
for(int t = 1; t <= term; t++) { | |
principal *= interestRate; | |
} | |
return principal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment