...求出数组中元素的最大值和最小值,并在窗体上输出

发布网友 发布时间:2024-10-24 01:24

我来回答

3个回答

热心网友 时间:2024-11-07 10:21

Private Function MaxMin(intData() As Integer, Ncont As Integer, max As Integer, min As Integer)
max = intData(0)
min = intData(0)
For i = 0 To Ncont - 1
For j = 1 To Ncont
If max < intData(j) Then max = intData(j)
If min > intData(j) Then min = intData(j)
Next j
Next i
End Function
Private Sub Command1_Click()
Dim max As Integer
Dim min As Integer
Dim a(10) As Integer
For i = 0 To 9
a(i) = InputBox("请输入第" & i + 1 & "个整数!")
Print "a(" & i & ")=" & a(i)
Next i
Call MaxMin(a(), 9, max, min)
Print "max=" & max
Print "min=" & min
End Sub

热心网友 时间:2024-11-07 10:23

用JAVA 编写程序,从键盘读入10个整数存入数组,输出最大值,最小值及它们所在数组中的位置

import java.io.*;
import java.lang.*;
import java.util.StringTokenizer;
class array
{
public static void main(String args[])
{
StringTokenizer st=new StringTokenizer(\"10 20 30 40\");
String s=\"\";
int[] b=new int[10];
int Max=0,Min=0;
int count=0;
System.out.println(\"输入10个数字用空格隔开如:1 10 31 45 57 6 70 18 29 50\");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
st=new StringTokenizer(s);
}
catch(Exception e)
{
System.out.print(e.getMessage());
}

while(st.hasMoreTokens())
{
b[count]=Integer.parseInt(st.nextToken());
count++;
}

Min=b[0];
for(int i=0;i<b.length;i++)
{
if(Max<b[i])
{
Max=b[i];
}

else if(Min>b[i])
{
Min=b[i];
}
}
System.out.println(\"Max:\"+Max);
System.out.println(\"Min:\"+Min);
}
}

热心网友 时间:2024-11-07 10:24

'a better one
Private Function mm(s() As Integer, n As Integer, max As Integer, min As Integer)
max = s(1)
min = s(1)
For i = 2 To n
If max < s(i) Then max = s(i)
If min > s(i) Then min = s(i)
Next i
End Function

Private Sub Form_Click()
Dim max As Integer
Dim min As Integer
Dim a(1 To 10) As Integer
For i = 1 To 10
a(i) = InputBox("请输入第" & i & "个整数", "输入框")
Print "a(" i ")=" & a(i)
Next i
Call mm(a(), 10, max, min)
Print "max=" & max
Print "min=" & min
End Sub
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com