Created
July 24, 2014 15:35
-
-
Save MeilCli/299f52a2029aeba347d4 to your computer and use it in GitHub Desktop.
20の階乗
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package longCover; | |
public class Main{ | |
public static void main(String[] args){ | |
try{ | |
longTest(20); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
try{ | |
doubleTest(20); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} | |
/*/ | |
* long test | |
* 1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20=2432902008176640000 | |
* long max-l=6790470028678135807 | |
* double test | |
* 1.0*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20=2.43290200817664E18 | |
* double max-d=1.7976931348623157E308 | |
*/ | |
} | |
public static void longTest(int cnt){ | |
long l = 1; | |
System.out.println("long test"); | |
System.out.print(l); | |
for(int i = 2;i<=cnt;i++){ | |
System.out.print('*'); | |
System.out.print(i); | |
l = l*i; | |
} | |
System.out.print('='); | |
System.out.println(l); | |
System.out.print("long max-l="); | |
System.out.println(Long.MAX_VALUE-l); | |
} | |
public static void doubleTest(int cnt){ | |
double d = 1; | |
System.out.println("double test"); | |
System.out.print(d); | |
for(int i = 2;i<=cnt;i++){ | |
System.out.print('*'); | |
System.out.print(i); | |
d = d*i; | |
} | |
System.out.print('='); | |
System.out.println(d); | |
System.out.print("double max-d="); | |
System.out.println(Double.MAX_VALUE-d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doubleよくわかんない()