Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java 入門
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javatest;
/**
*
* @author ogaaaan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int val1 = 0;
int val2 = 0;
String ope;
int kekka = 0;
if(args.length != 3) {
System.out.println("Usage : java dentaku 数値 演算子 数値");
System.out.println("演算子は kake waru tasu hiku の4つです");
System.exit(0);
}
val1 = Integer.parseInt(args[0]);
val2 = Integer.parseInt(args[2]);
ope = args[1];
if(ope.equals("tasu")) {
kekka = val1 + val2;
}
if(ope.equals("hiku")) {
kekka = val1 - val2;
}
if(ope.equals("kake")) {
kekka = val1 * val2;
}
if(ope.equals("waru")) {
kekka = val1 / val2;
}
System.out.println(val1+" "+ope+" "+val2+""+kekka+" です");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment