大家好:
今天在逛百度的時候有位芝麻問了個問題,感覺他是一個初學者!把他的代碼添枝加葉了一下成了下面幾個程序!大家共勉一下吧!
共 五 個方法:
//格式4 * 3 * 2 * 1 = 24
//從零到九相加為13的數
//九九乘方表
//數組排序
//反向輸出字符串我把這些方法整合了,控制台輸入輸出打印!
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner inRecurrence =new Scanner(System.in);
System.out.println("請輸入您需要計算成績的起始數,回車結束 :");
long n = recurrence(inRecurrence.nextInt());
System.out.println(n);
getForString();
printString();
Scanner inShuzu =new Scanner(System.in);
int[] shuzu=new int[3];
System.out.println("請輸入3個數比較");
for(int i=0;i//從零到九相加為13的數
private static void getForString(){
System.out.println("從零到九相加為13的數:");
for(int a=0 ; a<=9 ; a++){
for(int b=0; b<=9 ; b ++){
if(a+b == 13){
System.out.println("a="+a+" "+"b="+b+" ");
}
}
}
}//九九乘方表
private static void printString(){
System.out.println("九九乘方表:");
for(int i = 1; i <= 9 ; i ++){
for(int j = 1 ; j <= i; j ++){
System.out.print(j+"*"+i+"="+i*j+" ");
}
System.out.println();
}
System.out.println("九九乘方表已經結束!");
}
//數組排序
private static int compute(int[] in){
System.out.println("數組排序:");
int temp = 0;
for(int i = 0; i < in.length ; i ++){
for(int j = 0 ; j < in.length ; j ++){
if(in[i] > in[j]){
temp = in[i];
in[i] = in[j];
in[j] = temp;
}
}
}
for(int k = 0 ; k < in.length ; k ++){
System.out.print(in[k] + ",");
}
System.out.println("排序結束!");
return Math.abs(in[0] - in[in.length - 1]);
} //反向輸出字符串
private static void getString(String str){
System.out.println("反向輸出字符串!");
if(str != null && !str.isEmpty()){
for(int i = str.length() - 1; i >= 0; i-- ){
System.out.print(str.charAt(i));
}
}
}
}
結果為:
請輸入您需要計算成績的起始數,回車結束 :
4
4 * 3 * 2 * 1 = 24
從零到九相加為13的數:
a=4 b=9
a=5 b=8
a=6 b=7
a=7 b=6
a=8 b=5
a=9 b=4
九九乘方表:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
九九乘方表已經結束!
請輸入3個數比較
3 6 8
數組排序:
8,6,3,排序結束!
sdee333
反向輸出字符串!
333eeds