打印等腰三角形
| public class test { |
| public static void main(String[] args) { |
| |
| int a = 3; |
| |
| System.out.println(); |
| System.out.print(" "); |
| System.out.print(" "); |
| System.out.print("*"); |
| |
| System.out.println(); |
| System.out.print(" "); |
| System.out.print("*"); |
| System.out.print("*"); |
| System.out.print("*"); |
| |
| System.out.println(); |
| System.out.print("*"); |
| System.out.print("*"); |
| System.out.print("*"); |
| System.out.print("*"); |
| System.out.print("*"); |
| |
| } |
| } |
| public class test { |
| public static void main(String[] args) { |
| |
| int a = 3; |
| |
| System.out.println(); |
| for (int i=1; i<=2; i++){ |
| System.out.print(" "); |
| } |
| for (int i=1; i<=1; i++){ |
| System.out.print("*"); |
| } |
| |
| System.out.println(); |
| for (int i=1; i<=1; i++){ |
| System.out.print(" "); |
| } |
| for (int i=1; i<=3; i++){ |
| System.out.print("*"); |
| } |
| |
| System.out.println(); |
| for (int i=1; i<=0; i++){ |
| System.out.print(" "); |
| } |
| for (int i=1; i<=5; i++){ |
| System.out.print("*"); |
| } |
| |
| } |
| } |
| public class test { |
| public static void main(String[] args) { |
| |
| int a=5; |
| |
| int b=1; |
| for (int j=a; j>=1; j--){ |
| System.out.println(); |
| for (int i=1; i<j; i++){ |
| System.out.print(" "); |
| } |
| for (int i=1; i<=b; i++){ |
| System.out.print("*"); |
| } |
| b+=2; |
| } |
| |
| } |
| } |
打印九九乘法表
| public class test { |
| public static void main(String[] args) { |
| System.out.println(); |
| System.out.print(1 + "*" + 1 + "=" + 1*1); |
| System.out.print(","); |
| |
| System.out.println(); |
| System.out.print(1 + "*" + 2 + "=" + 1*2); |
| System.out.print(","); |
| System.out.print(2 + "*" + 2 + "=" + 2*2); |
| System.out.print(","); |
| |
| System.out.println(); |
| System.out.print(1 + "*" + 3 + "=" + 1*2); |
| System.out.print(","); |
| System.out.print(2 + "*" + 3 + "=" + 2*3); |
| System.out.print(","); |
| System.out.print(3 + "*" + 3 + "=" + 3*3); |
| System.out.print(","); |
| |
| } |
| } |
| public class test { |
| public static void main(String[] args) { |
| int j=0; |
| |
| j++; |
| System.out.println(); |
| for (int i=1; i<=j; i++){ |
| System.out.print(i + "*" + j + "=" + i*j); |
| System.out.print(","); |
| } |
| |
| j++; |
| System.out.println(); |
| for (int i=1; i<=j; i++){ |
| System.out.print(i + "*" + j + "=" + i*j); |
| System.out.print(","); |
| } |
| |
| j++; |
| System.out.println(); |
| for (int i=1; i<=j; i++){ |
| System.out.print(i + "*" + j + "=" + i*j); |
| System.out.print(","); |
| } |
| |
| } |
| } |
| public class test { |
| public static void main(String[] args) { |
| int j=0; |
| for (int n=1; n<=9; n++){ |
| j++; |
| System.out.println(); |
| for (int i=1; i<=j; i++){ |
| System.out.print(i + "*" + j + "=" + i*j); |
| System.out.print(","); |
| } |
| } |
| |
| } |
| } |
求和
- 给定一个整数,求出每个位数的和,例如:1234,结果:1+2+3+4=10
- 第1次推导
| public class test { |
| public static void main(String[] args) { |
| |
| int a=12; |
| int b=a/10; |
| int c=a%10; |
| System.out.println(b + "," + c); |
| |
| int a=123; |
| int b=a/100; |
| int c=a/10; |
| int c1=c%10; |
| int d=a%10; |
| System.out.println(b + "," + c + "," + c1 + "," + d); |
| |
| int a=1234; |
| int b=a/1000; |
| int c=a/100; |
| int c1=c%10; |
| int d=a/10; |
| int d1=d%10; |
| int e=a%10; |
| System.out.println(b + "," + c + "," + c1 + "," + d + "," + d1 + "," + e); |
| |
| } |
| } |
| public class test { |
| public static void main(String[] args) { |
| int a=12345; |
| int sum=0; |
| int n=get0(a); |
| |
| int m = get1(n); |
| int f=a/m; |
| System.out.println(f); |
| sum+=f; |
| |
| for(int j=n-1; j>1; j--){ |
| int p=a/get1(j); |
| int p1=p%10; |
| System.out.println(p1); |
| sum+=p1; |
| } |
| |
| int e=a%10; |
| System.out.println(e); |
| sum+=e; |
| System.out.println(sum); |
| } |
| |
| |
| public static int get0(int a){ |
| int b; |
| int i=1; |
| do{ |
| b = a/10; |
| a = b; |
| System.out.println(b); |
| i++; |
| }while (a>10); |
| System.out.println("b小于10" + "," + i); |
| return i; |
| } |
| |
| |
| public static int get1(int n){ |
| int m=1; |
| for(int i=1; i<n; i++){ |
| m*=10; |
| } |
| System.out.println(m); |
| return m; |
| } |
| |
| } |
| public class test { |
| public static void main(String[] args) { |
| int a = 12365; |
| int sum=0; |
| do{ |
| sum+=a%10; |
| a=a/10; |
| }while (a>0); |
| System.out.println(sum); |
| |
| } |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-09-29 马踏棋盘算法
2022-09-29 弗洛伊德算法
2022-09-29 迪杰斯特拉算法