(1)用四种方式输出九九乘法表
package com.nyj;
public class Chengfabiao {
public static void main(String[] args) {
test1();
test2();
test3();
test4();
}
private static void test4() {
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
System.out.print(i+"*"+j+"="+i*j+" ");
}
System.out.println();
}
System.out.println("****************************");
}
private static void test3() {
for(int i=9;i>0;i--){
for(int j=1;j<=i;j++){
System.out.print(i+"*"+j+"="+i*j+" ");
}
System.out.println();
}
System.out.println("****************************");
}
private static void test2() {
for(int i=1;i<=9;i++){
for(int k=0;k<9-i;k++){
System.out.print("\t");
}
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+" \t");
}
System.out.println();
}
System.out.println("****************************");
}
private static void test1() {
for(int i=9;i>0;i--){
for(int k=0;k<9-i;k++){
System.out.print("\t");
}
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
System.out.println("****************************");
}
}```
****(2)数组排序以及复制输出****
public class Paixu2 {
public static void main(String[] args) {
int[] sort={1789,2035,1899,1456,2013,1458,2458,1254,1472,2365};
String[] str={"Java","Python","PHP","C#","C Programming","C++"};
int max = sort[0];
int min = sort[0];
int sum = 0;
for(int i=0;i<sort.length;i++){
if(max<sort[i]){
max=sort[i];
}
if(min>sort[i]){
min=sort[i];
}
sum+=sort[i];
}
System.out.println("最大值为 "+max);
System.out.println("最小值为 "+min);
System.out.println("总和为 "+sum);
System.out.print("整型数组排序前 : ");
for(int i=0;i<sort.length;i++){
System.out.print(sort[i]+"\t");
}
Arrays.sort(sort);
System.out.print("\n"+"整型数组排序后 : ");
for(int i=0;i<sort.length;i++){
System.out.print(sort[i]+"\t");
}
System.out.print("\n"+"字符串数组排序前 : ");
for(int i=0;i<str.length;i++){
System.out.print(str[i]+"\t");
}
Arrays.sort(str);;
System.out.print("\n"+"字符串数组排序后 : ");
for(int i=0;i<str.length;i++){
System.out.print(str[i]+"\t");
}
int[] sort1=Arrays.copyOf(sort, sort.length);
System.out.println("\n"+"复制后的整型数组"+Arrays.toString(sort1));
String[] str1=Arrays.copyOf(str, str.length);
System.out.println("复制后的字符串数组"+Arrays.toString(str1));
}
}