You are on page 1of 6

!

"#$%&'# )
LxLend Lhe program below wlLh a do-whlle loop such LhaL all odd numbers beLween 0 and
x+1 ls wrlLLen on Lhe ouLpuL. WlLh x = 19, Lhe followlng ouLpuL should be produced:



public static void main(String[] args) {
int x = 20;
int abbruch = 1;

}
!"#$%&'# *
As ln Lxerclse 1, buL use a whlle-loop.

!"#$%&'# +
As ln Lxerclse 1, buL use a for-loop.

!"#$%&'# ,
LxLend Lhe program below Lo produce Lhe followlng ouLpuL:



public static void main(String[] args) {
System.out.print("Geben Sie eine ungerade Zahl ein: ");
for(){

}
}

!"#$%&'# -
As ln Lxerclse 4, buL use a whlle-loop.





!"#$%&'# .
LxLend Lhe program below Lo generaLe Lhe followlng ouLpuL:





public static void main(String[] args) {
System.out.print("Geben Sie eine Zahl ein: ");

for(){
System.out.println();
}
}

!"#$%&'# /
ln Lhe program below, replace xxxxxxxxx wlLh a useful sLaLemenL Lo make Lhe program work.
1he program/loop should LermlnaLe when Lhe user enLers Lhe number 100.

public static void main(String[] args) {
System.out.print("Geben Sie eine Zahl ein: ");
for(int eingabe = In.readInt(); eingabe != 100; xxxxxxxxx){
System.out.println("Zahl: " + eingabe);
System.out.print("Geben Sie eine Zahl ein: ");
}
}






!"#$%&'# 0
LxLend Lhe program below wlLh a for-loop Lo creaLe a sLalrcase-llke paLLern ln Lhe ouLpuL
area. WlLh counLer = 16, 12, or 8 Lhe followlng ouLpuLs should be produced:


counLer = 16 counLer = 12 counLer = 8

public static void main(String[] args) {
int counter = 15;

for(){

}
}

!"#$%&'# 1
8eplace xxx and yyy below Lo wrlLe Lhe word 'kLACLnlu81' on Lhe ouLpuL (do noL make any
oLher changes Lo Lhe program!).

public static void main(String[] args) {
char[] array = {'L', 'G', 'N', 'U', 'T', 'R', 'F', 'E', 'A', 'K'};

for(xxx; yyy; i--){
System.out.print(array[i] + "" + array[array.length-1-i]);
}
}












!"#$%&'# )2
llrsL, 3&45674 lmplemenLlng and LesLlng Lhe program below, declde whaL ouLpuL wlll be
produced!

public static void main(String[] args) {
for(int i = 0; i < 100; i++){
if(i == 74){
break;
}
if(i % 9 != 0){
continue;
}
System.out.println(i);
}
System.out.println("----------------");
int f = 0;
while(true){
f++;
int j = f * 30;
if(j == 1260){
break;
}
if(f % 10 != 0){
continue;
}
System.out.println(f);
}
}


!"#$%&'# ))
llrsL, 3&45674 lmplemenLlng and LesLlng Lhe program below, declde whaL ouLpuL wlll be
produced. Second, lf Lhe break sLaLemenL ls deleLed, whaL ouLpuL wlll now be dlsplayed?

public static void main(String[] args) {
for(int i = 1; i < 10; i++){
int temp = 0;
for(int j = i; j < 10; j++){
temp = temp + j;
if(temp % 2 == 0){
break;
}
System.out.print(j + " ");
}
System.out.println();
}
}







!"#$%&'# ))



!"#$%&'# )*
Clven ls Lhe followlng array, or any oLher lnL-array of lengLh !.

int[] array = {1,1,8,4,2,6};

WrlLe a program whlch calculaLes Lhe sum of Lhe values ln all cells of Lhe array LhaL have an
odd lndex-number. A correcL program would end up wlLh Lhe value 11 for Lhe above
example.






!"#$%&'# )+
Clven ls Lhe followlng array, or any oLher lnL-array wlLh lengLh !, where !2 = 0.

int[] array = {1,5,8,4,2,6,9,10};

WrlLe a program whlch palr-wlse shlfLs Lhe array conLenL of Lwo nelghborlng cells.
AfLer execuLlon Lhe conLenL of Lhe example array above should be:

{5,1,4,8,6,2,10,9};

!"#$%&'# ),
Clven ls Lhe followlng array, or any oLher lnL-array.

int[] array = {1,5,8,4,2};

WrlLe a program whlch shlfLs Lhe conLenL of Lhe array wlLh one poslLlon Lo Lhe rlghL (Lhe lasL
elemenL ls placed aL lndex 0). AfLer execuLlon Lhe conLenL of Lhe example array above should
be:

{2,1,5,8,4};

!"#$%&'# )-
Clven ls Lhe followlng array, or any oLher lnL-array.

int[] array = {1,5,8,4,2};

WrlLe a program whlch flnds Lhe largesL number ln Lhe array and puLs Lhls value ln Lhe lasL
cell. 1he orlglnal value ln Lhe lasL cell ls placed aL Lhe lndex on whlch Lhe largesL number was
found. AfLer execuLlon Lhe conLenL of Lhe example array above should be:

{1,5,2,4,8};

!"#$%&'# ).
Clven are Lhe followlng arrays, or any oLher lnL-array wlLh lengLh !, where !2 != 0.

int[] array1 = {1,2,3,4,5,6,7};
int[] array1 = {1,2,3,4,5};

WrlLe a program whlch prlnLs ouL Lhe conLenL of Lhe array (each cell value should be prlnLed
on a separaLe llne) sLarLlng wlLh Lhe mlddle cell, worklng lLs way sLepwlse lefL, Lhen rlghL.
AfLer execuLlon Lhe conLenL of Lhe example array above should be:

lor array1: lor array2
4 3
3 2
5 4
2 1
6 5
1
7

You might also like