肖sir__java___编程练习题1

1、编写一个java程序输入”dcs“

案例:

package com.company.phone;

public class java_输出语句 {
    public static void main(String[] args) {
        System.out.println("dcs");
    }
}

2、1!+2!+3!+4!+......+10!的和

 

1
2
3
4
5
6
7
8
9
10
11
12
13
public class java_输出语句 {
    public static void main(String[] args) {
        int  i,j, m,sum=0;
        for (i=1;i<11;i++){
            m=1;
            for (j=1;j<11;j++){
                m=m*j;
            }
            sum=sum+m;
        }
        System.out.println(sum);
    }
}

 3、计算两个整数的和

1
2
3
4
5
6
7
8
9
10
11
12
//
import java.util.Scanner;
public class java_输出语句 {
    public static void main(String[] args) {
        Scanner  input  =new Scanner(System.in);
        System.out.println("请输入两个整数:");
        int  x=input.nextInt();
        int y=input.nextInt();
        int sum =x+y;
        System.out.println(sum);
    }
}

  4、计算两个数的最大值

复制代码
import java.util.Scanner;
public class java_输出语句 {
    public static void main(String[] args) {
        Scanner  input  =new Scanner(System.in);
        System.out.println("请输入两个整数:");
        int  x=input.nextInt();
        int y=input.nextInt();
        int  max=0;
        if (x>y){
            max=x;
        }
        else {
            max =y;
        }
        System.out.println(max
        );
    }
}

复制代码

  5、统计1~100之间出现了几次数字9

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//#统计1~100之间出现了几次数字9
import java.util.Scanner;
public class java_输出语句 {
    public static void main(String[] args) {
     int count=0;
     for  (int  i=1;i<=100;i++){
         if  (i%10==9){
             //查看个位是不是9
             count++;
         }
         else if (i/10==9){
             //十位是不是9
             count++;
         }
     }
        System.out.println(count);
    }
}

  

posted @   xiaolehua  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示