Created
March 11, 2012 12:11
-
-
Save L3au/2016216 to your computer and use it in GitHub Desktop.
我靠刚才写的表述没了。。。就一些判断完全权平方数,回文数神马的。
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
public class Multiplication{ | |
//输出左对齐,给定字符串长度,不足补空格 | |
public static String len(String str, int i){ | |
String tmp = ""; | |
if(str.length() < String.valueOf(i).length() * 4 + 8){ | |
for (int j = 0; j < String.valueOf(i).length() * 4 + 8 - str.length();j++ ) { | |
tmp += " "; | |
} | |
} | |
str += tmp; | |
return str; | |
} | |
//输出左对齐,给定字符串长度,从头填充 | |
public void m1(){ | |
int [][] a = new int[90][]; | |
StringBuffer sb = new StringBuffer(); | |
for(int i = 0; i < a.length; i++){ | |
a[i] = new int[i+1]; | |
for(int j =0; j < a[i].length ; j++){ | |
for(int k = 0; k < String.valueOf(a.length).length() * 4 + 8; k++){ | |
sb.append(" "); | |
} | |
a[i][j] = (i+1)*(j+1); | |
System.out.print(sb.replace(0,((j+1)+" * "+(i+1)+" = "+a[i][j]).length(),(j+1)+" * "+(i+1)+" = "+a[i][j])); | |
sb = new StringBuffer(""); | |
} | |
System.out.println(); | |
} | |
} | |
//判断回文数(平方回文) | |
public void m2(){ | |
int n = 0; | |
for (int i = 1; i <= 1.0e4 ; i++ ) { | |
String s = String.valueOf(i); | |
if (new StringBuffer(s).reverse().toString().equalsIgnoreCase(s) && m3(i)) { | |
System.out.println(i); | |
} | |
} | |
//System.out.println(); | |
} | |
//判断完全平方数 | |
public boolean m3(int n){ | |
double fsqrt = java.lang.Math.sqrt(n); | |
return (int) fsqrt == fsqrt; | |
} | |
//递归求n! | |
public int f(int n){ | |
int result; | |
if (n == 1) return 1; | |
result = f(n - 1) * n; | |
return result; | |
} | |
public static void main(String [] args){ | |
Multiplication mp = new Multiplication(); | |
//mp.m1(); | |
mp.m2(); | |
System.out.println(mp.f(9)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment