http://oshiete1.goo.ne.jp/kotaeru_reply.php3?q=5416746
public class homework {
/**
* @param args
*/
public static void main(String[] args) {
func(1173);
System.out.println("-----");
func(36);
}
public static int[] check(int prime, int div){ //再帰処理
if(prime%div==0 && prime > div && div > 1){
return new int[]{prime/div,div};
}else if(div * div > prime){
return new int[]{prime,0};
}else{
return check(prime, div + 1);
}
}
public static void func(int prime){ //再帰処理
int[] ret =check(prime,2);
if(ret[1]==0){//case prime
System.out.println(ret[0]+" is prime");
return;
}
System.out.println(prime+"="+ret[0]+"*"+ret[1]+"; are thse factors either prime or products of rime?");
//case squared
if(ret[0]==ret[1]){
func(ret[0]);
System.out.println(prime+" is "+ret[0]+" squared, ie the product of prime numbers or prime numbers together.");
return;
}
//case other
func(ret[0]);
func(ret[1]);
System.out.println("So "+prime+" is the product of prime numbers together. (Between "+ret[0]+" and "+ret[1]+" is the product of prime or prime)");
return;
}
}
public class homework {
/**
* @param args
*/
public static void main(String[] args) {
func(1173);
System.out.println("-----");
func(36);
}
public static int[] check(int prime, int div){ //再帰処理
if(prime%div==0 && prime > div && div > 1){
return new int[]{prime/div,div};
}else if(div * div > prime){
return new int[]{prime,0};
}else{
return check(prime, div + 1);
}
}
public static void func(int prime){ //再帰処理
int[] ret =check(prime,2);
if(ret[1]==0){//case prime
System.out.println(ret[0]+" is prime");
return;
}
System.out.println(prime+"="+ret[0]+"*"+ret[1]+"; are thse factors either prime or products of rime?");
//case squared
if(ret[0]==ret[1]){
func(ret[0]);
System.out.println(prime+" is "+ret[0]+" squared, ie the product of prime numbers or prime numbers together.");
return;
}
//case other
func(ret[0]);
func(ret[1]);
System.out.println("So "+prime+" is the product of prime numbers together. (Between "+ret[0]+" and "+ret[1]+" is the product of prime or prime)");
return;
}
}
戻り先はここです。
関数 public static void func(int prime){ //再帰処理
の最初で呼び出しています。
なるほど。 int[] と配列で割る数と割られる数を格納、でしたか。
一つ質問させて下さい。
return new int[]{prime/div,div};
この戻り値は、どこに戻っているのでしょうか?