Skip to content
Snippets Groups Projects
Commit 44d3aaa5 authored by Eemeli Eronen's avatar Eemeli Eronen
Browse files

harjotus 1 eka epätoivone yritys

parent 76d629b2
No related branches found
No related tags found
No related merge requests found
public class tehtava12ab {
public static void main(String[] args) {
int[] testi = {0,1,2,6,7};
int[] testi2 = {4,3,1};
System.out.println(onkoLajiteltu(testi));
System.out.println("-----------");
System.out.println(monotonisuusTesti(testi2));
}
public static boolean onkoLajiteltu(int[] list) {
boolean lajiteltu = true;
for(int i = 0;i<list.length-1;i++) {
if (list[i] > list[i+1]) {
lajiteltu = false;
}
}
return lajiteltu;
}
public static int monotonisuusTesti(int[] list) {
boolean aidostikasvava = true;
boolean aidostivaheneva = true;
for(int i = 0;i<list.length-1;i++) {
if (list[i] >= list[i+1]) {
aidostikasvava = false;
}
}
for(int i = 0;i<list.length-1;i++) {
if (list[i] <= list[i+1]) {
aidostivaheneva = false;
}
}
if(aidostikasvava) {
return 1;
}
else if(aidostivaheneva) {
return -1;
}
else {return 0;}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment