Skip to content

Instantly share code, notes, and snippets.

@siritori
Created May 20, 2014 01:53
Show Gist options
  • Save siritori/2e8f000c4b4d93f06d14 to your computer and use it in GitHub Desktop.
Save siritori/2e8f000c4b4d93f06d14 to your computer and use it in GitHub Desktop.
情報科学I
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;
}
}
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