if,switch,for循环语句
来源:互联网 发布:java list排序算法 编辑:程序博客网 时间:2024/05/19 18:37
public class Test01 {
/**
* if,switch,for循环语句
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
choose1(75);
choose2(3);
int[][] arr=new int[][]{{2,34},{1,153},{23,45,345},{232,22}};
loop(arr);
int[] arr2=new int[]{2,34,23,124,43,33};
sort(arr2);
}
// 冒泡排序
public static void sort(int[] arr2) {
for (int i = 0; i < arr2.length-1; i++) {//比较的轮数
for (int j = 0; j < arr2.length-1-i; j++) {//比较的次数
if (arr2[j]>arr2[j+1]) {
int temp=arr2[j];//交换位置
arr2[j]=arr2[j+1];
arr2[j+1]=temp;
}
}
}
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
}
// 循环遍历二维数组
public static void loop(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.println(arr[i][j]);
}
}
}
// if 判断语句
private static void choose1(int number) {
if(90<=number&&number<=100){
System.out.println("成绩优秀!");
System.out.println("再接再厉!");
}
else if (80<=number&&number<=89){
System.out.println("成绩优良!");
}
else if (60<=number&&number<=79){
System.out.println("成绩及格!");
}
else if (0<=number&&number<=59){
System.out.println("成绩不及格!");
}
else {
System.out.println("您输入的成绩有误!");
}
}
// switch 选择语句
public static void choose2(int number){
switch(number){ //switch语句慧聪number开始执行,一直到碰到break;或者执行到结尾才结束
case 1:
System.out.println("不通过");
break;
case 2:
System.out.println("不通过");
break;
case 3:
System.out.println("待定");
break;
case 4:
System.out.println("通过");
break;
case 5:
System.out.println("通过");
break;
default:
System.out.println("您输入的分数有误");
break;
}
}
}
/**
* if,switch,for循环语句
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
choose1(75);
choose2(3);
int[][] arr=new int[][]{{2,34},{1,153},{23,45,345},{232,22}};
loop(arr);
int[] arr2=new int[]{2,34,23,124,43,33};
sort(arr2);
}
// 冒泡排序
public static void sort(int[] arr2) {
for (int i = 0; i < arr2.length-1; i++) {//比较的轮数
for (int j = 0; j < arr2.length-1-i; j++) {//比较的次数
if (arr2[j]>arr2[j+1]) {
int temp=arr2[j];//交换位置
arr2[j]=arr2[j+1];
arr2[j+1]=temp;
}
}
}
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
}
// 循环遍历二维数组
public static void loop(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.println(arr[i][j]);
}
}
}
// if 判断语句
private static void choose1(int number) {
if(90<=number&&number<=100){
System.out.println("成绩优秀!");
System.out.println("再接再厉!");
}
else if (80<=number&&number<=89){
System.out.println("成绩优良!");
}
else if (60<=number&&number<=79){
System.out.println("成绩及格!");
}
else if (0<=number&&number<=59){
System.out.println("成绩不及格!");
}
else {
System.out.println("您输入的成绩有误!");
}
}
// switch 选择语句
public static void choose2(int number){
switch(number){ //switch语句慧聪number开始执行,一直到碰到break;或者执行到结尾才结束
case 1:
System.out.println("不通过");
break;
case 2:
System.out.println("不通过");
break;
case 3:
System.out.println("待定");
break;
case 4:
System.out.println("通过");
break;
case 5:
System.out.println("通过");
break;
default:
System.out.println("您输入的分数有误");
break;
}
}
}
0 0
- if,switch,for循环语句
- JavaScript-for循环语句,if语句,switch语句
- 分支语句 循环语句 if,switch,do,while,for分析
- python_3(循环语句、if、switch、for、break、冒泡算法)
- 循环控制语句for while do-while if switch
- 流程控制陷阱(Switch语句,标签,if语句,for循环,foreach循环的循环计数器)
- Matlab的if语句switch语句for循环while循环语句练习
- matlab if&&for&&switch语句
- Lesson_for_java_day05--java的三目运算符、if语句、switch语句、while循环、for循环
- 选择 | 循环 | 语句(if,if……else,switch,while,for)的理解和使用
- if和switch语句、循环语句while和do……while、for
- 实战数组,for循环 if语句 switch语句 制作一个小明的成绩管理系统
- switch语句与for循环
- Go语言学习笔记 --- 控制语句之if判断,循环语句for, switch语句和跳转语句
- 分支结构、循环结构流控语句(if、switch、for、while)
- 分支语句(if,switch case)、循环(for,while,do while)、continue、break、随机数
- if和switch和for语句
- If 判断、switch语句和三中循环语句
- Android:传感器编程
- 在iphone越狱机器中使用Hook
- 最新Android 4.x 搭建开发环境
- 解压Windows的install.wim文件
- MYSQL中'TYPE=MyISAM'错误的解决方案
- if,switch,for循环语句
- ubuntu设置开机启动图形应用程序,替换默认图形桌面
- Qt - QTimer更新ui
- C++实现开机启动
- HDU 1082
- size_type与size_t的机器无关性
- poj 3320 Jessica's Reading Problem
- POJ 1006 Biorhythms
- LeetCode: Max Points on a Line