You are on page 1of 33

Structureren van werk

! "
#
$ %

& " ' (


) * )
+ ,- ,.

+ ,- ,/ 0 1 2
Structureren van werk

34 " 5

6 1 2 37 $89 9
: %

; " !
#

#
&

( <
!
package jle07;
import java.util.Scanner;

public class Berekening1 {

public static void main(String[] args)


{

int getal1, getal2;


int keuze, resultaat;
Scanner input = new Scanner(System.in);
System.out.print("geef een eerste getal op>");
getal1 = input.nextInt();
System.out.print("geef een tweede getal op>");
getal2 = input.nextInt();
System.out.println("kies een berekening");
System.out.println("1 = optelling; 2 = aftrekking");
System.out.println("3 = deling; 4 = vermenigvuldiging");
System.out.print("gewenste berekening>");
keuze = input.nextInt();
resultaat = bereken(getal1, getal2, keuze);
System.out.printf("het resultaat is %d\n",resultaat);

} /* main ()*/
Structureren van werk

public static int bereken(int x, int y, int z)


{
if (z == 1)
{
return (x + y);
}
else if (z == 2)
{
return (x - y);
}
else if (z == 3)
{
return (x / y);
}
else if (z == 4)
{
return (x * y);
}
else
return (0);
}

} /* class Berekening1*/

! 1 2 # 5

! "

;
0 9

# &
!
Structureren van werk

1 ) 9

int getal1, getal2;

= ! 5
public static int bereken(int x, int y, int z)

( 9

- )
public Static

! int

#
void $ %

8
# 5
$ % 0 #
2<> ? # @
6

#$
Structureren van werk

!
9 )
>
public static int bereken(int x, int y, int z)

; :9
:9 6
if (z == 1)
return (x + y);
> :9 (
:9 !

resultaat = bereken(getal1, getal2, keuze);

! 2 < !
:9 1
:9 2 < !
% / /AA
! % "
9

; ! :
& ( )
:

package jle07;

public class Parameter01 {

public static void main (String[] args)


{

int x = 3;

System.out.println("voor oproep van wijzigWaarde, x = " + x);


wijzigWaarde(x);
System.out.println("na oproep van wijzigWaarde, x = " + x);

} /* main() */

// change parameter in passMethod()


public static void wijzigWaarde(int p) {
p = 10;
System.out.println("in wijzigWaarde, p = " + p);
}

} /* class Parameter01 */

0 # 5
voor oproep van wijzigWaarde, x = 3
in wijzigWaarde, p = 10
na oproep van wijzigWaarde, x = 3

B :

#
Structureren van werk

package jle07;

public class Parameter02 {

public static void main (String[] args)


{

int x = 3;

System.out.println("voor oproep van wijzigWaarde, x = " + x);


wijzigWaarde(x);
System.out.println("na oproep van wijzigWaarde, x = " + x);

} /* main() */

// change parameter in passMethod()


public static int wijzigWaarde(int p) {
p = 10;
System.out.println("in wijzigWaarde, p = " + p);
return(p);
}

} /* class Parameter02 */

# # :
voor oproep van wijzigWaarde, x = 3
in wijzigWaarde, p = 10
na oproep van wijzigWaarde, x = 10

&
Structureren van werk

"
C ' !
&
'( !

if (z == 1)
{
return (x + y);
}

if (z == 1)
return (x + y);

else -
!

" 6 30

3&
if (z == 1)
return (x + y);
else if (z == 2)
return (x - y);
else if ( (z == 3) && (y != 0))
return (x / y);
else if (z == 4)
return (x * y);
else
return (0);
Structureren van werk

" 5 "

public static int bereken(int x, int y, int z)


{
int resultaat;
switch(z)
{
case 1 :
resultaat = x + y;
break;
case 2 :
resultaat = x - y;
break;
case 3 :
if ( y != 0)
resultaat = x / y;
else resultaat = 0;
break;
case 4 :
resultaat = x * y;
default :
resultaat = 0;
} /* switch z */
return resultaat;
}

! 5
B
D
25 2E
<E
E
<5
E
>5
E
5 FFE
E

GHI IH

# 9 19 B /
C 9 C 9

)
Structureren van werk

+
1 2
public static int bereken(int x, int y, int z)
; public #
37 1 ?
1 2
package jle07;

public class Berekening4 {

public static void main (String[] args)


{
int resultaat;
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 4; j++)
{
resultaat = Berekening1.bereken(i, (i+1), j);
System.out.printf("resultaat is %d\n",resultaat);
}
}

} /* main () */

} /* class Berekening4 */

1 ?
6
0 : !
"

& , -

*
Structureren van werk

" private

package jle07;
import java.util.Scanner;

public class Berekening3 {

public static void main(String[] args)


{
int getal1, getal2;
int keuze, resultaat;
Scanner input = new Scanner(System.in);
System.out.print("geef een eerste getal op>");
getal1 = input.nextInt();
System.out.print("geef een tweede getal op>");
getal2 = input.nextInt();
System.out.println("kies een berekening");
System.out.println("1 = optelling; 2 = aftrekking");
System.out.println("3 = deling; 4 = vermenigvuldiging");
System.out.print("gewenste berekening>");
keuze = input.nextInt();
resultaat = bereken(getal1, getal2, keuze);
System.out.printf("het resultaat is %d\n",resultaat);
} /* main ()*/

private static int bereken(int x, int y, int z)


{
int resultaat;
switch(z)
{
case 1 :
resultaat = x + y;
break;
case 2 :
resultaat = x - y;
break;
case 3 :
if ( y != 0)
resultaat = x / y;
else resultaat = 0;
break;
case 4 :
resultaat = x * y;
default :
resultaat = 0;
} /* switch z */
return resultaat;
}
} /* class Berekening3 */

! 1 > 1 >
" 5

.
Structureren van werk

1 ? <

int resultaat2 = Berekening1.

C 1 2 #
1 2" 5 >
E

) "
J 1 > 1 >
; #
5

* "

& @
0 5

0
!
" B
Structureren van werk

/
/ # "
; > "
5 '
B 2 F 0

package jle07;
import java.util.Scanner;

public class Som1 {

public static void main (String[] args)


{
int som=0, i=1;
int getal;
Scanner input = new Scanner(System.in);

while (i < 10)


{
System.out.printf("Geef een %de getal op >", i);
getal = input.nextInt();
som = som + getal;
i++;

} /* while i < 10 */
System.out.printf("Totaal van alle getallen is %d\n",som);
} /* main() */
} /* class Som1 */
#
while (voorwaarde)
{

}
8
" 5 '
package jle07;
import java.util.Scanner;

public class Som2 {

public static void main (String[] args)


{
int som=0, i=1;
int getal;
Scanner input = new Scanner(System.in);

do
{
System.out.printf("Geef een %de getal op >", i);
getal = input.nextInt();
som = som + getal;
i++;

} while (som < 100) ;


System.out.printf("Totaal van alle getallen is %d\n",som);
} /* main() */
} /* class Som2 */
Structureren van werk

! ' ' 5
do
{

} while (voorwaarde)

; ' ' ' 1 '


. 1 ' '
;
5 ' ' '
.

B < 233 ;
;
#
Geef een 1e getal op >1
Geef een 2e getal op >2
Geef een 3e getal op >3
Geef een 4e getal op >4
Geef een 5e getal op >5
Geef een 6e getal op >6
Geef een 7e getal op >7
Geef een 8e getal op >8
Geef een 9e getal op >9
Geef een 10e getal op >10
Geef een 11e getal op >11
Geef een 12e getal op >12
Geef een 13e getal op >13
Geef een 14e getal op >14
Totaal van alle getallen is 105

; !

.
Structureren van werk

# 5 ;
2 2K

package jle07;

public class Som3 {

public static void main (String[] args)


{
int som = 0;
for (int i = 1; i <= 15; i++ )
{
som += i;
}
System.out.printf("som is %d\n", som);

} /* main() */

} /* class Som3 */

! for

' <
( )

package jle07;

public class Som4 {

public static void main (String[] args)


{
int som = 0;
for (int i = 1, j=2 ; i <= 15 ; i++, j++ )
{
som += i * j;
System.out.printf("som is opgehoogd met product
van %d en %d ( %d) tot %d\n",
i, j, i*j, som);

}
System.out.printf("som is %d\n", som);

} /* main() */

} /* class Som4 */
Structureren van werk

" (

" ) 5

int som = 0;
for (int i = 1, j=2 ; (i <= 15 && j<=20) ; i++, j++ )
{
som += i * j;
System.out.printf("som is opgehoogd met
product van %d en %d ( %d) tot %d\n",
i, j, i*j, som);

}
System.out.printf("som is %d\n", som);

( LL MN <3 *
2K <3 2K !

for (int i = 1, j=2 ; i <= 15 ; i++, j++ )

#
Structureren van werk

! ' $ % ;
" 1
B 1 ) 1 . B 1

C B
E
!

for (int i = 1; i <= 15; i++ )


!

# $ % 5 !
' 1

! '
package jle07;
public class Som3b {

public static void main (String[] args)


{
int som = 0;
int i = 1;
for ( ; i <= 15; i++ )
{
som += i;
}
System.out.printf("som is %d\n", som);
i = 5;
} /* main() */
} /* class Som3 */

& ' -
' 5 MN 2K
E
; ' ! N KE

&
Structureren van werk

& @&
# " 9
9 ; "

# !
;
" #
5 (

C 5
;

! 0

;
6
!
& @! * / */
!

&

public static void main (String[] args)


{
Scanner input = new Scanner(System.in);
int teller1, teller2, teller3, teller4;
int som = 0;
int product = 1;
int antwoord = 1;

do {
teller1 = toonBoodschap(1 );
teller2 = toonBoodschap(2 );
teller3 = toonBoodschap(3 );
teller4 = toonBoodschap(4 );
Structureren van werk

& 1

private static int toonBoodschap(int teller)


{

switch (teller)
{
case 1 : System.out.print("Geef een eerste startgetal op>");
break;
case 2 : System.out.print("Geef een eerste eindgetal op>");
break;
case 3 : System.out.print("Geef een tweede startgetal op>");
break;
case 4 : System.out.print("Geef een tweede eindgetal op>");
break;
default : System.out.print("onvoorzien geval");
break;

} /* switch (teller) */

if (teller <= 4)
{
return (input.nextInt());
}

1 5
% %! 5
1 #

package jle07;
import java.util.Scanner;

public class Som5 {

public static void main (String[] args)


{
Scanner input = new Scanner(System.in);
int teller1, teller2, teller3, teller4;
int som = 0;
int product = 1;
int antwoord = 1;

do {
teller1 = toonBoodschap(1, input);
teller2 = toonBoodschap(2, input);
teller3 = toonBoodschap(3, input);
teller4 = toonBoodschap(4, input);

for (int i = teller1; i <= teller2; i++ )


{
som += i;
}
System.out.printf("som is %d\n", som);
for (int j = teller3; j <= teller4; j++)
{
product *= j;
}
System.out.printf("product is %d\n", product);
System.out.printf("wilt u nogmaals berekenen (1 = ja) ?");
antwoord = input.nextInt();
} while (antwoord == 1) ;

} /* main() */
)
Structureren van werk

private static int toonBoodschap(int teller, Scanner opgave)


{

switch (teller)
{
case 1 : System.out.print("Geef een eerste startgetal op>");
break;
case 2 : System.out.print("Geef een eerste eindgetal op>");
break;
case 3 : System.out.print("Geef een tweede startgetal op>");
break;
case 4 : System.out.print("Geef een tweede eindgetal op>");
break;
default : System.out.print("onvoorzien geval");
break;

} /* switch (teller) */

if (teller <= 4)
{
return (opgave.nextInt());
}
else
{
return (0);
}

} /* toonBoodschap */

} /* class Som4 */

*
Structureren van werk

0
# 5 9 ! 9
9 : " ! #

"
! #
# 9 5 '
<3 2

C # 9
# (B&
E
( # 5 #
; # $ % $ %

B K &

0 B K
Geef een eerste startgetal op>4
Geef een eerste eindgetal op>6
Geef een tweede startgetal op>20
Geef een tweede eindgetal op>22
som is 15
product is 9240
wilt u nogmaals berekenen (1 = ja) ?
0 (
5
wilt u nogmaals berekenen (1 = ja) ?1
Geef een eerste startgetal op>4
Geef een eerste eindgetal op>6
Geef een tweede startgetal op>20
Geef een tweede eindgetal op>22
som is 30
product is 85377600
wilt u nogmaals berekenen (1 = ja) ?

0
) # !

.
Structureren van werk

C )
& ) E

' $B %

!
5

; #
# "

#
Structureren van werk

&

5
Structureren van werk

& !

2
Structureren van werk

# ?A KA 4

& !
Structureren van werk

# ;
2I<3

<3I<2

C 5 !

#
Structureren van werk

-
" " B!J "
" B!J ! '
" B!J "
"
! ," B#

" K3 $ %
0 C

&
Structureren van werk

! ' "
'

; " K3 - '
: ! P

! : Q
'
' '

" $ %
& B !
J Q LR

O B
Structureren van werk

! $B % ' B

! $ : % # B

" #

( "
HII S
S 5
S 5
S 5

)
Structureren van werk

! " ;
1 2 37
package jle07;
import java.util.Scanner;

/** De class Berekening vraagt 2 getallen aan de gebruiker


* en een derde getal dat aangeeft om welke berekening het gaat
* @author GC1494
* @version 1.0
*
*
*/

public class Berekening1 {

/** de methode bereken() aanvaardt 3 gehele getallen.


* Het laatste getal geeft aan om welke bewerking het gaat :
* 1 = optellen; 2 = aftrekken; 3 = delen; 4 = vermenigvuldigen
* @param x eerste getal
* @param y tweede getal
* @param z getal dat aangeeft om welke bewerking het gaat
*/
public static int bereken(int x, int y, int z)

#
; 1 , 5 ;8(Q'

*
Structureren van werk

1 ' - " '


HII IH

0 +
$ %

"Q#
; '
: ! :
: 37 J 1 32
$ % #
"

.
Structureren van werk

C " 5
5
HH H< H H H :
( 5 5
HH H
Structureren van werk

You might also like