
不知為啥函數居然會跟BufferedReader衝...,要讓函數過只能把函數放在throws IOException之上囧所以乾脆用比較習慣的物件來寫了
然後果然又有幾個for被卡了,懶得改了(茶)
import java.io.*;
class ste{
static long[] mul(long n,String as){
long[] a = new long[as.length()];
long[] b = new long[a.length*2];
for(int i=0;i<as.length();i++){
a[i] = n%10;
n /= 10;
}
for(int x=0;x<a.length;x++)
for(int y=0;y<a.length;y++)
b[x+y] += a[x]*a[y];
for(int i=0;i<b.length-1;i++){
long temp = b[i];
b[i] %= 10;
b[i+1] = b[i+1]+temp/10;
}
return b;
}
}
public class homework9458050_7{
public static void main(String[] alio)
throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("請輸入n值:");
String as = br.readLine();
long n = Long.parseLong(as);
long[] st = ste.mul(n,as);
System.out.println("n平方為:");
if(st[st.length-1] != 0)
System.out.print(st[st.length-1]);
for(int i=st.length-2;i>=0;i--)
System.out.print(st[i]);
System.out.println();
}
}
找時間去這家店看看好了