2个回答
展开全部
public class Max {
public static void main(String[] args) {
int[] a = new int[5];
System.out.println("请输入五个数:");
Scanner in=new Scanner(System.in);
int max = 0,n=0;
for(int i = 0;i < 5 ;i++) {
System.out.println("输入第" + (i+1) +"个数 :");
String readLine = in.nextLine();
a[i] = Integer.parseInt(readLine);
}
for(int i = 0; i < 5 ;i++) {
if(max < a[i]) {
max = a[i];
n=i+1;
}
}
System.out.println("最大数是" + max +";第" + n +"个数");
}
}
public static void main(String[] args) {
int[] a = new int[5];
System.out.println("请输入五个数:");
Scanner in=new Scanner(System.in);
int max = 0,n=0;
for(int i = 0;i < 5 ;i++) {
System.out.println("输入第" + (i+1) +"个数 :");
String readLine = in.nextLine();
a[i] = Integer.parseInt(readLine);
}
for(int i = 0; i < 5 ;i++) {
if(max < a[i]) {
max = a[i];
n=i+1;
}
}
System.out.println("最大数是" + max +";第" + n +"个数");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.*;
public class AN {
public static void main(String args[]) {
System.out.println("请输入5个整型数:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] a = new int[5];
int i;
int max = a[0];
int index = 0;
for (i = 0; i < 5; i++) {
try {
System.out.print("第" + (i + 1) + "个数据:");
a[i] = Integer.parseInt(br.readLine());
} catch (IOException e) {
}
}
for (i = 0; i < 5; i++) {
if (max < a[i]) {
max = a[i];
index = i;
}
}
System.out.print("最大数是:" + max);
System.out.println("\t序号是:" + (index+1));
}
}
public class AN {
public static void main(String args[]) {
System.out.println("请输入5个整型数:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] a = new int[5];
int i;
int max = a[0];
int index = 0;
for (i = 0; i < 5; i++) {
try {
System.out.print("第" + (i + 1) + "个数据:");
a[i] = Integer.parseInt(br.readLine());
} catch (IOException e) {
}
}
for (i = 0; i < 5; i++) {
if (max < a[i]) {
max = a[i];
index = i;
}
}
System.out.print("最大数是:" + max);
System.out.println("\t序号是:" + (index+1));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |