import java.util.Scanner;
class Forxunhuan{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//控制台输出1-10
for (int i = 1;i <= 10 ;i++ ) {
System.out.println(i);
}
System.out.println("--------------------------------");
//控制台输出10-1
for (int i = 10;i >= 1 ;i-- ) {
System.out.println(i);
}
System.out.println("--------------------------------");
//求1-100的和
int sum=0;
for (int i = 1;i <= 100 ; i++) {
sum += i;
}
System.out.println("1-100的和为:" + sum);
System.out.println("--------------------------------");
//水仙花数
System.out.println("百位数的水仙花数:");
for (int i = 100; i <= 999 ;i++ ) {
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100 % 10;
if (i == ge * ge *ge + shi * shi * shi + bai * bai * bai ) {
System.out.println(i);
}
}
System.out.println("--------------------------------");
//求水仙花个数
System.out.println("百位数的水仙花数有多少个");
int count = 0;
for (int i = 100; i <= 999 ;i++ ) {
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100 % 10;
if (i == ge * ge *ge + shi * shi * shi + bai * bai * bai ) {
count++;
}
}
System.out.println(count);
System.out.println("--------------------------------");
//用while语句求1--100的和
int sum1 = 0;
int l = 1;
while (l <= 100) {
sum1 += l;
l++;
}
System.out.println("1--100的和为:" + sum1);
System.out.println("--------------------------------");
//打印四行五列的星星
System.out.println("打印四行五列星星");
for (int i = 1;i <= 5 ;i++ ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print("*");
}
System.out.println();
}
System.out.println("--------------------------------");
//打印倒直角三角形
for (int i = 5 ; i >=1 ; i-- ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print("*");
}
System.out.println();
}
System.out.println("--------------------------------");
//输入两个数,返回较大值
int max = da (34,43);
System.out.println(max);
System.out.println("--------------------------------");
//输入两个数,比较是否相等
boolean d = deng (34,33);
System.out.println(d);
System.out.println("--------------------------------");
//打印三角形
System.out.println("请输入三角形的行数");
int a = sc.nextInt();
xing(a);
System.out.println("--------------------------------");
//打印九九乘法表
System.out.println("请输入你想打印的乘法表");
int biao = sc.nextInt();
print99(biao);
}
public static int da (int a,int b){
int max = (a > b)? a : b;
return max;
}
public static boolean deng(int a,int b) {
boolean d = (a == b) ? true : false;
return d;
}
public static void xing (int a ) {
for (int i = 1; i <= a ; i++ ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print("*");
}
System.out.println();
}
}
public static void print99(int a) {
for (int i = 1;i <= a ;i++ ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print(j + "*" + i + "=" + (j * i) + '\t');
}
System.out.println();
}
}
}
|
|