public?static?void?main(String[]?args)
成都創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)與策劃設(shè)計,左貢網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:左貢等地區(qū)。左貢做網(wǎng)站價格咨詢:18982081108
{
System.out.println("1000以內(nèi)符合條件轎激的臺階數(shù)如下:");
for?(int?i?=?7;?i?梁帆賀?1000;?i++)
{
/**?下面對應(yīng)各個條件,為了方便閱讀,我分開寫了?*/
if?(i?%?2?==?1)
{
if?(i?%?3?==?2)
{
if?(i?%?5?==?4)
{
if?(i?%?6?==?5)
{
if?(i?%?7?==?0)
{
System.out.println(i);
}
}
}
}
橡派????????}
}
}
public?class?Test?{
public?static?void?main(String[]?args)?{
for?(int?i?=?1;?i?=?9;?i++)?{
for?(int?j?=?1;?j?=?i;?j++)?{?//?此循環(huán)是打印?1×n?2×n?……?n×n?的這樣一行
System.out.print(j?+?"×"?+?i?+?"="?+?(i?*?j)?+?"\t");
}
System.out.println();?//?換行
}
}
}
效果:
一定要用遞歸的就這樣寫:
public class Test{
static final int s = 10; //自碧乎茄定義的臺階數(shù)
static int len = 0, sum = 0;
static int step[] = new int[s];
static void compute(final int stair) {
if(stair0) return;
if(stair==0) {
printSum();
sum++;
return;
}
for(int i = 1; i = 3; i++) {
step[len] = i;
len++;
compute(stair-i);
len--;
}
}
static void printSum() {
System.out.print("走法:");
for(int i = 0; i len; i++)
System.out.print(step[i]+ "悔察 ");
System.out.println();
}
public static void main(String args[]){
compute(s);
System.out.println("共有" + sum + "種走法頃雹");
}
}
循環(huán),,,,,好多循環(huán),,,,哇,,,,實現(xiàn)了空鬧
#includestring.h
#includeiostream
#includestack
using namespace std;
int main()
{
int n = 0, m = 0, sum = 0, cnt = 0;
cout "輸入明虧鬧階梯數(shù):" 激罩 endl;
cin n;
cout "輸入最多爬的階梯數(shù):" endl;
cin m;
if (n = 0)
{
cout "就一種,上去了!" endl;
}
if (m = 0)
{
cout "你想上是不可能的!" endl;
}
int i;
stackint sk;
do
{
if (sum = n)
{
++cnt;
while (sum = n)
{
sk.push(1);
++sum;
}
}
if (!sk.empty())
{
sum -= sk.top();
sk.pop();
}
else
{
cout cnt endl;
return 0;
}
HHH:
if (!sk.empty())
{
i = sk.top();
}
else
{
cout cnt endl;
return 0;
}
if (i m)
{
++i;
}
else
{
if (!sk.empty())
{
sum -= sk.top();
sk.pop();
goto HHH;
}
else
{
cout cnt endl;
return 0;
}
}
if (!sk.empty())
{
sum -= sk.top();
sk.pop();
}
else
{
cout cnt endl;
return 0;
}
sk.push(i);
sum += i;
} while (1);
return 0;
}