2017-01-08 6 views
1

2つの整数を生成していましたが、分割しました。私は2つの整数を整数または10進数で区切った結果を確認したい。次に、結果を比較しようとし、結果をこのコードで文字列に統合しますが、その動作は停止します。除算の結果がintか浮動小数点かどうかを確認する方法

Random r = new Random(); 
int first = r.nextInt(50 - 1) + 1; 

Random z = new Random(); 
int twond = z.nextInt(50 - 1) + 1; 

float Resultas = (first/twond); 
Result = (int) Resultas; 
String floatResult = Float.toString(Resultas); 

while (floatResult != String.valueOf(Result)) { 
    Random s = new Random(); 
    first = s.nextInt(50 - 1) + 1; 

    Random y = new Random(); 
    twond = y.nextInt(50 - 1) + 1; 

    Resultas = (first/twond); 
    Result = (int) Resultas; 
    floatResult = Float.toString(Resultas); 
} 
+1

使用[TypeVariable(https://developer.android.com/reference/java/lang/reflect/TypeVariable.html).. –

+0

なぜ作業コードを停止します。例外が発生し、これをあなたの質問に追加できますか? [質問する](http://stackoverflow.com/help/how-to-ask)をお読みください。 –

+0

H. Pauwelyn私はあなたが話していることを理解していません。 – Fachri

答えて

3
if (first % twond == 0) { 
    // result is an integer 
} 
+0

私はしようとしていました:while(first%twond!= 0){}私は整数結果を得るために最初と二番目を再生成したいからです。しかし、それはまだ動作していません。 – Fachri

+1

@Fachri ...なぜあなたはそれを簡単にして、単に整数を生成し、別の生成された整数でそれを倍数化してみませんか? – Karakuri

+0

Karakuri @私は最初のintとtwond intが必要な数学クイズを作りたいです。 – Fachri

関連する問題