Javaセミナー2014/上野真世
import java.io.*;
class HW20141216
{
public static void main(String args[]) throws IOException
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("整数を入力してください");
String str = br.readLine();
String ans = "";
int i = 2;
int num = Integer.parseInt(str);
while(i <= num)
{
//iが素数かを判断。
if(i != 2)
{
int m =(int)Math.sqrt(i);
for(int j = 2; j <= m;j++)
{
if(m%j == 0)
continue;
}
}
if(num%i != 0)
{
i++;
continue;
}
else
{
ans += String.valueOf(i) + " x ";
num = num/i;
}
}
System.out.println(str + " = " + ans.substring(0,ans.length()-3));
}
catch(NumberFormatException e)
{
System.out.println("数値を入力してください");
}
}
}