Program 1:
package afterfeb13;public class secondgreater {public static void main(String[] args) {int[] mark = { 200, 100, 78, 89, 102 };int highest = 0, second_highest = 0, third_highest = 0;for (int i = 0; i < mark.length; i++) {if (mark[i] > highest)// 56>0//100>56---//102>100{second_highest = highest;highest = mark[i];} else if (mark[i] > second_highest) {third_highest = second_highest;second_highest = mark[i];} else if (mark[i] > third_highest) {third_highest = mark[i];}}System.out.println("highest num = " + highest);System.out.println("second_highest = " + second_highest);System.out.println("third_highest = " + third_highest);}}package afterfeb13; public class secondgreater { public static void main(String[] args) { int[] mark = { 200, 100, 78, 89, 102 }; int highest = 0, second_highest = 0, third_highest = 0; for (int i = 0; i < mark.length; i++) { if (mark[i] > highest)// 56>0//100>56---//102>100 { second_highest = highest; highest = mark[i]; } else if (mark[i] > second_highest) { third_highest = second_highest; second_highest = mark[i]; } else if (mark[i] > third_highest) { third_highest = mark[i]; } } System.out.println("highest num = " + highest); System.out.println("second_highest = " + second_highest); System.out.println("third_highest = " + third_highest); } }package afterfeb13; public class secondgreater { public static void main(String[] args) { int[] mark = { 200, 100, 78, 89, 102 }; int highest = 0, second_highest = 0, third_highest = 0; for (int i = 0; i < mark.length; i++) { if (mark[i] > highest)// 56>0//100>56---//102>100 { second_highest = highest; highest = mark[i]; } else if (mark[i] > second_highest) { third_highest = second_highest; second_highest = mark[i]; } else if (mark[i] > third_highest) { third_highest = mark[i]; } } System.out.println("highest num = " + highest); System.out.println("second_highest = " + second_highest); System.out.println("third_highest = " + third_highest); } }
Enter fullscreen mode Exit fullscreen mode
Output:
highest num = 200
second_highest = 102
third_highest = 100
Program 2:
package afterfeb13;public class smallestnum {public static void main(String[] args) {int[] mark = { 200, 100, 78, 89, 102 };int small = mark[0];for (int i = 0; i < mark.length; i++) {if (mark[i] < small) {small = mark[i];}}System.out.println(small);}}package afterfeb13; public class smallestnum { public static void main(String[] args) { int[] mark = { 200, 100, 78, 89, 102 }; int small = mark[0]; for (int i = 0; i < mark.length; i++) { if (mark[i] < small) { small = mark[i]; } } System.out.println(small); } }package afterfeb13; public class smallestnum { public static void main(String[] args) { int[] mark = { 200, 100, 78, 89, 102 }; int small = mark[0]; for (int i = 0; i < mark.length; i++) { if (mark[i] < small) { small = mark[i]; } } System.out.println(small); } }
Enter fullscreen mode Exit fullscreen mode
Output:
78
Program 3:
package afterfeb13;public class numberequal {public static void main(String[] args) {int[] mark = { 90, 81, 82, 90, 90 };String[]subject= {"tamil","english","maths","social","science"};int count = 0;for (int i = 0; i < mark.length; i++)if (mark[i] == 90) {System.out.println(subject[i]+"="+mark[i]);count++;}System.out.println("count = " + count);}}package afterfeb13; public class numberequal { public static void main(String[] args) { int[] mark = { 90, 81, 82, 90, 90 }; String[]subject= {"tamil","english","maths","social","science"}; int count = 0; for (int i = 0; i < mark.length; i++) if (mark[i] == 90) { System.out.println(subject[i]+"="+mark[i]); count++; } System.out.println("count = " + count); } }package afterfeb13; public class numberequal { public static void main(String[] args) { int[] mark = { 90, 81, 82, 90, 90 }; String[]subject= {"tamil","english","maths","social","science"}; int count = 0; for (int i = 0; i < mark.length; i++) if (mark[i] == 90) { System.out.println(subject[i]+"="+mark[i]); count++; } System.out.println("count = " + count); } }
Enter fullscreen mode Exit fullscreen mode
Output:
tamil=90
social=90
science=90
count = 3
原文链接:array mark ,equal mark,small mark,highest mark, second highest mark
© 版权声明
THE END
暂无评论内容