九九乘方表/数组排序/反向输出字符串
来源:互联网 发布:淘宝子账号手机登陆 编辑:程序博客网 时间:2024/04/30 07:00
大家好:
今天在逛百度的时候有位芝麻问了个问题,感觉他是一个初学者!把他的代码添枝加叶了一下成了下面几个程序!大家共勉一下吧!
共 五 个方法:
<span style="font-size: 18px;">//格式4 * 3 * 2 * 1 = 24</span>
<span style="font-size: 18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">从零到九相加为13的数</span>
<span style="font-size: 18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">九九乘方表</span>
<span style="font-size: 18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">数组排序</span>
<span style="font-size: 18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">反向输出字符串</span>我把这些方法整合了,控制台输入输出打印!
<span style="font-size:18px;">import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner inRecurrence =new Scanner(System.in);System.out.println("请输入您需要计算成绩的起始数,回车结束 :");long n = recurrence(inRecurrence.nextInt());System.out.println(n);getForString();printString(); Scanner inShuzu =new Scanner(System.in);int[] shuzu=new int[3];System.out.println("请输入3个数比较"); for(int i=0;i<shuzu.length;i++){ shuzu[i]=inShuzu.nextInt();}compute(shuzu);Scanner zifuchuan =new Scanner(System.in);System.out.println("请输入反向输出的字符串");getString(zifuchuan.nextLine());}//格式4 * 3 * 2 * 1 = 24private static long recurrence(int n){if(n == 1){System.out.print("1 = ");return 1;}else{System.out.print(n+" * ");return n * recurrence(n -1);}}</span>
<span style="font-size:18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">从零到九相加为13的数</span><span style="font-size:18px;">private static void getForString(){System.out.println("从零到九相加为13的数:");for(int a=0 ; a<=9 ; a++){for(int b=0; b<=9 ; b ++){if(a+b == 13){System.out.println("a="+a+" "+"b="+b+" "); }}}}</span>
<span style="font-size:18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">九九乘方表</span><span style="font-size:18px;">private static void printString(){ System.out.println("九九乘方表:");for(int i = 1; i <= 9 ; i ++){for(int j = 1 ; j <= i; j ++){System.out.print(j+"*"+i+"="+i*j+" "); }System.out.println();}System.out.println("九九乘方表已经结束!");}//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">数组排序</span><span style="font-size:18px;">private static int compute(int[] in){System.out.println("数组排序:");int temp = 0;for(int i = 0; i < in.length ; i ++){for(int j = 0 ; j < in.length ; j ++){if(in[i] > in[j]){temp = in[i];in[i] = in[j];in[j] = temp;}}}for(int k = 0 ; k < in.length ; k ++){System.out.print(in[k] + ",");}System.out.println("排序结束!");return Math.abs(in[0] - in[in.length - 1]);}</span>
<span style="font-size:18px;">//</span><span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif;">反向输出字符串</span><span style="font-size:18px;">private static void getString(String str){System.out.println("反向输出字符串!");if(str != null && !str.isEmpty()){for(int i = str.length() - 1; i >= 0; i-- ){System.out.print(str.charAt(i));}}}}</span>结果为:
<span style="font-size:18px;">请输入您需要计算成绩的起始数,回车结束 :44 * 3 * 2 * 1 = 24从零到九相加为13的数:a=4 b=9 a=5 b=8 a=6 b=7 a=7 b=6 a=8 b=5 a=9 b=4 九九乘方表:1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 九九乘方表已经结束!请输入3个数比较3 6 8数组排序:8,6,3,排序结束!sdee333反向输出字符串!333eeds</span>
0 0
- 九九乘方表/数组排序/反向输出字符串
- 九九乘方表
- 九度1167 数组排序
- 九度oj1167数组排序
- 数组(九)
- 【九度】题目1167:数组排序
- 九度oj-1167-数组排序
- 九度OJ 题目1066:字符串排序
- 九度OJ 题目1135:字符串排序
- 九度OJ 1054 字符串内排序
- 九度题目:字符串排序(1135)
- 【九度】题目1054:字符串内排序
- 【九度】题目1135:字符串排序
- 九度OJ 1066: 字符串排序
- 九度OJ 1066 字符串排序
- 九度题目1054:字符串内排序
- 九度 题目1054:字符串内排序
- 九度OJ 1066 字符串排序
- startActivityForResult、setResult、onActivityForResult
- rails 文档在线预览方案
- 人脸检测——OpenCV的分类器的haar特征数据
- android中所有颜色代码
- windows socket 流式套接字笔记
- 九九乘方表/数组排序/反向输出字符串
- 2014科技大佬悲喜录:有人锒铛入狱有人睡不着觉
- android 反编译
- [LeetCode]Find Minimum in Rotated Sorted Array II
- Java的大内存分页支持
- 针对TCP/IP的调优
- 1501051659-hpu-1031 【C语言训练】求素数问题.cpp
- Java的浮点数计算问题
- Longest Valid Parentheses