肖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); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!