Немного переделал код public class Masiv public static void main Strin

 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Немного переделал код
public class Masiv {
public static void main(String[] args) {
String [] array=new String[5];
array[0]="John";
array[1]="Mary";
array[2]="Jane";
array[3]="Mike";
array[4]="Susie";
String name;
int n=-1;//Я изменил инициализацию итератора
for(int i=0; i<array.length; i++){
n++;
if(n==20){break;}//Для наглядности модифицировал ограничитель
if(i==0){name=array[i]; System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name);
continue;}
if(i==1){name=array[i-1];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name);
continue;}
if(i==2){name=array[i-1];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name);
continue;}
if(i==3){name=array[i-1];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name);
continue;}
if(i==4){name=array[i-3];System.out.print("n = "+n+" i = "+i+" : ");System.out.println(name); i--; }
if(n==5){name=array[n-4];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name); i--; continue;}
if(n==6){name=array[n-3];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name); i--; continue;}
if(n==7){name=array[n-4];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name); i--; continue;}
if(n==8){name=array[n-4];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name); i--; continue;}
if(n==9){name=array[n-9];System.out.print("n = "+n+" i = "+i+" : "); System.out.println(name); i--; continue;}
}
}
}
-----------------------------------------
АНАЛИЗ АЛГОРИТМА
КОД ВЫВОДИТ ЗНАЧЕНИЯ КАК
--------------
n = 0 i = 0 : John
n = 1 i = 1 : John
n = 2 i = 2 : Mary
n = 3 i = 3 : Jane
n = 4 i = 4 : Mary
n = 5 i = 4 : Mary
n = 5 i = 3 : Mary
n = 6 i = 3 : Jane
n = 7 i = 4 : Mary
n = 7 i = 3 : Mike
n = 8 i = 3 : Jane
n = 9 i = 4 : Mary
n = 9 i = 3 : John
n = 10 i = 3 : Jane
n = 11 i = 4 : Mary
n = 12 i = 4 : Mary
n = 13 i = 4 : Mary
n = 14 i = 4 : Mary
n = 15 i = 4 : Mary
n = 16 i = 4 : Mary
n = 17 i = 4 : Mary
n = 18 i = 4 : Mary
n = 19 i = 4 : Mary
------------------
Подумай и напиши код, который бы выводил нужный нам результат как
John
John
Mary
Jane
Mary
Mary
Mike
Susie
John
-------------------------