# 高手

www.MyException.Cn  网友分享于：2013-04-28  浏览：0次

if (a== 0) {
if (data == tempRowCount) {
/*
*当程序执行到这里时，下面两种情况为什么不一样？？？？求高手指点一下。
**/
//1、第一种情况跳出整个if else块
result = result.substring(1, result.length());
return result;
//2、第二种情况会执行到codeXXXX()处
return result.substring(1, result.length());
}else{

}
}else{
codeXXXX();
}

------解决方案--------------------
Java code
```package com;

public class QualityFactorTest {
static String result = "";
static int rowCount = 2;

public static void main(String[] args) {
getQualityFactor(12);
System.out.println(result);
System.out.println(getQualityFactor1(12));
System.out.println(getQualityFactor2(12));
}
//递归调用实现
private static void getQualityFactor(int data) {
if(data == 1) {//说明因式分解结束
result = result.substring(1);
rowCount = 2;
}
for(; rowCount <= data; rowCount++) {
if(data % rowCount == 0) {
result = "*" + rowCount + result;
getQualityFactor(data / rowCount);
break;
//return;
}
}
}
//递归调用实现
private static String getQualityFactor1(int data) {
for(; rowCount <= data; rowCount++) {
if(data % rowCount == 0) {
if(data == rowCount) {//说明因式分解结束
String result1 = String.valueOf(rowCount);
rowCount = 2;
return result1;
}
String result1 = "*" + rowCount;
return  getQualityFactor1(data / rowCount) + result1;
}
}
return "";
}
//循环实现
private static String getQualityFactor2(int data) {
String result1 = "";
while(true) {
for(; rowCount <= data; rowCount++) {
if(data % rowCount == 0) {
result1 = "*" + rowCount + result1;
data = data / rowCount;
break;
}
}
if(data == 1) {
break;
}
}
return result1.substring(1);
}
}```