Άσκηση Java



Αξιολόγηση Χρήστη:  / 0
ΧειρότεροΚαλύτερο 
Λεπτομέρειες
Κατηγορία: Java
Δημιουργηθηκε στις Δευτέρα, 29 Σεπτεμβρίου 2014 16:52
Τελευταία Ενημέρωση στις Τρίτη, 11 Νοεμβρίου 2014 15:26
Δημοσιεύτηκε στις Τρίτη, 11 Νοεμβρίου 2014 15:26
Γράφτηκε από τον/την Σωτηρης
Εμφανίσεις: 9624

Άσκηση στην Java που να δέχεται έναν πίνακα 5 θέσεων και να βρίσκει το μέγιστο και τον ελάχιστο αριθμό άλλα και την θέσει τους μέσα στον πίνακα 

import java.util.Scanner;
public class Example{
public static void main (String [] args)
{
int A[]=new int [5];
int i;
int max,min;
int thesi1,thesi2;
thesi1=0;
thesi2=0;
max=A[0];
min=A[0];
Scanner in = new Scanner(System.in);
for(i=0;i<A.length;i++)
{
System.out.print("Dwse ena arithmo :");
A[i]=in.nextInt();
}
for(i=0;i<A.length;i++)
{
if(A[i]>max)
{
max=A[i];
thesi1++;
}
else if(A[i]<min)
{
min=A[i];
thesi2++;
}
}
System.out.println("O megistos arithmos einai : "+max+" kai briskete sthn thesi :"+thesi1);
System.out.println("O mikroteros arithmos einai :"+min+" kai brisketai sthn thesi :"+thesi2);
}
}