Write a java program that declares an array of 10 integers. Then, find and print the maximum number in the array
- برمجة جافا
- 2022-04-19
- softwareEngineer
الأجوبة
part 1:
public class Main
{
public static void main(String[] args) {
int a[]={3,5,1,7,5,2,54,77,2,45};
int max=a[0];
for(int i=0; i<a.length;i++)
{
if(a[i]>max)
max=a[i];
}
System.out.println("highest number in the array is "+max);
}
}
part 2 (using a method):
public class Main
{
public static void main(String[] args) {
int a[]={3,5,1,7,5,2,54,77,2,45};
maximum(a[]);
}
public static void maximum(int []a)
{
int max=a[0];
for(int i=0; i<a.length;i++)
{
if(a[i]>max)
max=a[i];
}
System.out.println("highest number in the array is "+max);
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال