java数组2
来源:互联网 发布:淘宝双11宣传视频 编辑:程序博客网 时间:2024/06/06 09:48
利用数组求出最大值最小值
public class Test{
public static void main(String[]args){
int score[]={12,55,54,23,65,23};
int max=0; //定义变量保存最大值
int min=0;
max=min=score[0]; //把第一个元素的内容复制给max和min
for(int x=0;x<score.length;x++){ //循环求出最大最小
if(score[x]>max){//依次判断后续元素是否比max大
max=score[x];}//如果大则修改最大值内容
if(score[x]<min){
min=score[x];}
}
System.out.println(max+""+min); //输出最大值最小值
}
}
-----------------------------
利用数组排序
public class Test{
public static void main(String[]args){
int score[]={12,42,43,61,13,5};
for(int i=1;i<score.length;i++){
for(int j=0;j<score.length;j++){
if(score[i]<score[j]){
int temp=score[i];
score[i]=score[j];
score[j]=temp;
}
}
}
for(int i=1;i<score.length;i++){
System.out.println(score[i]);
}
}
}
0 0
- Java心得--数组2
- java的数组(2)
- 数组2-JAVA
- java--数组2
- java-数组2
- java学习-数组2
- java数组2
- Java数组2
- 2 java数组总结
- java 数组练习题2
- java 基础知识2 --数组
- JAVA题目-数组2
- JAVA基础(2) 数组Arrays
- java---数组的学习2
- Java数组-冒泡排序2
- Java 数组练习题(2)
- Java学习笔记2--数组
- JAVA学习笔记(2)--数组
- HDU 4708:Rotation Lock Puzzle
- 题目1025:最大报销额 学习
- shell时间差计算
- Leetcode 15. 3Sum
- JVM加载机制
- java数组2
- 正则表达式——完美验证
- 笔试题43. LeetCode OJ (30)
- 《啊哈算法》第五章 图的遍历
- [AngularJS 1] Introduction to AngularJS
- SPOJ GSS1 Can you answer these queries I
- 友元
- hiho#1049 : 后序遍历( nyoj848 STBE)
- js的string对象