- 757 名前:デフォルトの名無しさん mailto:sage [2008/04/28(月) 17:40:14 ]
- >>755
public class Power { public static void main(String[] args) { boolean isCorrectInteger = true; boolean isCorrectDouble = true; for(int i = 1; i <= 40; i++){ int resultOfInt = 1; double resultOfDouble = 1; for(int j = 0; j < i; j++){ resultOfDouble *= 3; resultOfInt *= 3; } System.out.println(String.format("k=%1$2d, int=%2$11d, double=%3$20.0f",i, resultOfInt, resultOfDouble)); if(checkError(String.format("%1$1d", Math.abs(resultOfInt))) && isCorrectInteger){ System.out.println("Overflow"); isCorrectInteger = false; } if(checkError(String.format("%1$1.0f", resultOfDouble)) && isCorrectDouble){ System.out.println("Error"); isCorrectDouble = false; } } } private static boolean checkError(String string) { int val = 0; for(int k = 0; k < string.length(); k++){ val += Integer.parseInt(string.substring(k, k+1)); } return (val % 3) != 0; } }
|

|