-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.siOrdenado.java
62 lines (53 loc) · 1017 Bytes
/
6.siOrdenado.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//int[] arrayTest = {8,7,6};
//int[] arrayTest = {1,2,3,4,11,12,15,16,17,2001};
//int[] arrayTest = {8,8,8,8,8};
int[] arrayTest = {1,2,3,8,9,8,7,6};
verificaOrden(arrayTest);
}
public static void verificaOrden(int[] array)
{
boolean igual = true;
boolean cre = true;
boolean des = true;
//verifico si los números son todos iguales.
for(int i=0; i<array.length-1;i++)
{
int primero = array[0];
if(array[i+1]!=primero) //para que no se compare con el mismo.
{
igual=false;
}
if(array[i]>array[i+1])
{
cre=false;
}
if(array[i]<array[i+1])
{
des=false;
}
}
if(igual)
{
System.out.println("iguales");
}
else
{
if(cre==false && des==false)
{
System.out.println("desorden");
}
else if(cre)
{
System.out.println("creciente");
}
else if(des)
{
System.out.println("des");
}
}
}
}