文章标题
来源:互联网 发布:淘宝banner尺寸大小 编辑:程序博客网 时间:2024/06/14 19:44
我记得谭浩强那个版本的C语言是我学习失败的一种见证。当时里面的数组之后就是函数,而我并没有怎么敲代码,然后基本上该不会的还是不会。。。
今天敲的是最简单的数组的基本使用,包含了一些小的对于函数里面的使用
(1)求一个数中的最大数(最小数)
import java.util.*;public class ArrMax {public static void main(String[] args){Scanner a=new Scanner(System.in);double max=0;double score[]=new double[5];for(int i=0;i<score.length;i++){score[i]=a.nextDouble();if(max<score[i]){max=score[i];}else{score[i]=max;}}System.out.print(+max);}}
(2)给数组中插入一个元素( 先降序排列一波)
说实在的,前面求最大数真的比较简单,但是这个插入元素对我现在的水平来说应该是自己得思考一下,还没做,但是我觉得这个里面明确的一点应该是对于数组下标的掌握,毕竟插入了一个元素,数组里面要增加一个长度,给计算机里面开辟的空间也得增加。
import java.util.*;public class Arrsort_insert {public static void main(String[] args){Scanner a=new Scanner(System.in);int score[]=new int[6];score[0]=98;score[1]=267;score[2]=26;score[3]=35;score[4]=2;System.out.println("重新进行降序排列");for(int i=0;i<4;i++){for(int j=0;j<4-i;j++){if(score[j]<score[j+1]){int temp=score[j];score[j] = score[j+1]; score[j+1] = temp;}}}for(int c:score){System.out.print(c+"\t");}System.out.print("请输入您需要的数字");int num=a.nextInt();int index=score.length-1;for(int i=0;i<score.length;i++){if(num>score[i]){index=i;break;}}for(int i=score.length-1;i>index;i--){score[i]=score[i-1];}score[index]=num;System.out.println(score[index]);for(int c:score){System.out.print(c+"\t");}}}
(3)二维数组的使用 (计算三个班五名学生的成绩之和)
import java.util.*;public class TwoArr {public static void main(String[] args){int score[][]=new int[3][5];Scanner a=new Scanner(System.in);for(int i=0;i<score.length;i++){System.out.println("第"+(i+1)+"个班的成绩");int sum=0;for(int j=0;j<score.length;j++){System.out.print("第"+(j+1)+"个同学的成绩是:");score[i][j]=a.nextInt();sum+=score[i][j];}System.out.println("这个班的总成绩是"+sum);}}}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 第四届蓝桥杯第九题
- 树(1)---序论
- 影如人生
- 算法-快速排序(为什么每次都要从右边开始)
- golang日記ーsprint有什么用? 和+号的区别
- 文章标题
- 用bat命令重启explorer的方法
- Scala模式匹配
- MyFlag Step2:APP雏形的展现以及相关规范
- 因子分析、主成分分析(PCA)、独立成分分析(ICA)——斯坦福CS229机器学习个人总结(六)
- LeetCode (Merge Intervals)
- Java泛型_嵌套_其它
- 面试总结(4):top、left、right、bottom 和 translationX、translationY 和 scrollX,scrollY的区别
- 成功的人在多于2个方面都做的好