JAVA编程求大神帮忙解答下,谢谢!
题目1:循环输入5个数字,找出其中最低积分及其下标题目2:循环输入10个数字,统计合法数字(1,2,3)各出现的次数和非法数字出现的次数...
题目1:循环输入5个数字,找出其中最低积分及其下标
题目2:循环输入10个数字,统计合法数字(1,2,3)各出现的次数和非法数字出现的次数 展开
题目2:循环输入10个数字,统计合法数字(1,2,3)各出现的次数和非法数字出现的次数 展开
2个回答
2015-05-19 · 知道合伙人软件行家
关注
展开全部
第一题:
public class ClientMain {
public static void main(String[] args) {
System.out.println("请输入5个数:");
Scanner input = new Scanner(System.in);
int[] numList = new int[5];
for(int i=0;i<5;i++) {
numList[i] = input.nextInt();
}
int min = numList[0];
int count = 0;
for(int i=0;i<5;i++) {
if(min>numList[i]) {
min = numList[i];
count = i;
}
}
System.out.println("最低积分为:"+min+", 以及下标为:"+(count+1));
}
}
第二题:
public class ClientMain {
public static void main(String[] args) {
System.out.println("请输入10个数:");
Scanner input = new Scanner(System.in);
int[] numList = new int[10];
for(int i=0;i<10;i++) {
numList[i] = input.nextInt();
}
int num1=0,num2=0,num3=0,numOther=0;
for(int i=0;i<numList.length;i++) {
if(numList[i]==1) {
num1++;
} else if(numList[i]==2) {
num2++;
} else if(numList[i]==3) {
num3++;
} else {
numOther++;
}
}
System.out.println("数字1出现了:"+num1+"次,数字2出现了:"+num2+"次,数字3出现了:"+num3+"次,其他数字出现了:"+numOther+"次!");
}
}
展开全部
public class Main {
public static void main(String[] args) {
first();
second();
}
private static void second() {
Scanner scanner = new Scanner(System.in);
int num1 = 0, num2 = 0, num3 = 0, numother = 0, x;
for (int i = 0; i < 10; i++) {
x = scanner.nextInt();
if (x == 1) {
num1++;
}else if (x == 2){
num2 ++;
}else if (x == 3){
num3++;
}else {
numother++;
}
}
System.out.println("1出现的次数:"+num1);
System.out.println("2出现的次数:"+num2);
System.out.println("3出现的次数:"+num3);
System.out.println("非合法数字出现的次数:"+numother);
}
private static void first() {
int x = 99999, z;
int y = 0;
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
z = scanner.nextInt();
if (z < x) {
x = z;
y = i + 1;
}
}
System.out.println(x);
System.out.println(y);
}
}
public static void main(String[] args) {
first();
second();
}
private static void second() {
Scanner scanner = new Scanner(System.in);
int num1 = 0, num2 = 0, num3 = 0, numother = 0, x;
for (int i = 0; i < 10; i++) {
x = scanner.nextInt();
if (x == 1) {
num1++;
}else if (x == 2){
num2 ++;
}else if (x == 3){
num3++;
}else {
numother++;
}
}
System.out.println("1出现的次数:"+num1);
System.out.println("2出现的次数:"+num2);
System.out.println("3出现的次数:"+num3);
System.out.println("非合法数字出现的次数:"+numother);
}
private static void first() {
int x = 99999, z;
int y = 0;
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
z = scanner.nextInt();
if (z < x) {
x = z;
y = i + 1;
}
}
System.out.println(x);
System.out.println(y);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询