C++でexit()のような関数を使用して、プログラムの実行を異常終了させました。この関数はJavaで使用できます。 例: - 次のプログラムでは、iの値が最初に印刷されるとすぐに実行を終了します。Javaプログラムの実行を途中で終了させる方法は?
//following is the program :
class Lcm {
public static void main(String args[]) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
for (int i=1 ; i<=a*b ; i++) {
if (i%a==0 && i%b==0) {
System.out.println("lcm is: " + i);
/* i want to terminate the program
* when the value of i is printed
* for very 1st time
*/
}
}
}
}
}
あなたの質問は間違いなくフォーマットしてください。 – m0skit0
これはCとどのように関連していますか? – Praetorian