Você está na página 1de 3

Programação Orientada a Objetos

1. Identifique e corrija os erros em cada um dos seguintes conjuntos de código:


Identify and correct the errors in each of the following code sets:

a) while (c <= 5)
{
produto * = c;
++ c;

b) if (gender == 1)
System.out.println ("Woman");
else;
System.out.println ("Man");

2. Qual o resultado do seguinte programa?


What is the result of the following program?

3. Modifique o código fornecido para produzir a saída mostrada em cada alínea. Use
técnicas de indentação adequadas. Não faça outras alterações além de inserir
chavetas e indentação.
Modify the code provided to produce the output shown in each case. Use proper
indentation techniques. Do not make changes other than insert braces and indentation.

if (y == 8)
if (x == 5)
System.out.println ("@@@@@");
else
System.out.println ("#####");
System.out.println ("$$$$$");
System.out.println ("&&&&&");

a) Assumindo que x = 5 e y = 8, a seguinte saída é produzida:


Assuming that x = 5 and y = 8, the following output is produced:
@@@@@
$$$$$
&&&&&
Programação Orientada a Objetos

b) Assumindo que x = 5 e y = 8, a seguinte saída é produzida:


Assuming that x = 5 and y = 8, the following output is produced:
@@@@@

c) Assumindo que x = 5 e y = 7, a seguinte saída é produzida. [Nota: as últimas três


instruções de saída depois do else fazem parte de um bloco.]
Assuming that x = 5 and y = 7, the following output is produced. [Note: The last
three output statements after the else are part of a block.]
#####
$$$$$
&&&&&

4. Encontre e corrija o (s) erro (s) em cada um dos seguintes segmentos de


código:
Find and correct the error (s) in each of the following code segments:

a) For ( i = 100, i >= 1, i++ )


System.out.println( i );

b) O código a seguir deve ser impresso se o valor inteiro for ímpar ou par:
The following code should print if the integer value is odd or even:

switch ( value % 2 )
{
case 0:
System.out.println( "Even integer" );
case 1:
System.out.println( "Odd integer" );
}

c) O código a seguir deve mostrar os inteiros ímpares de 19 a 1:


The following code should show the odd integers from 19 to 1:

for ( i = 19; i >= 1; i += 2 )


System.out.println( i );

d) O código a seguir deve produzir os inteiros pares de 2 a 100:


The following code should produce the even integers from 2 to 100:

counter = 2;
do
{
System.out.println( counter );
counter += 2;
} While ( counter < 100 );
Programação Orientada a Objetos

5. Qual o resultado da seguinte sequencia de instruções?


What is the result of the following code segments?

for ( i = 1; i <= 5; i++ )


{
for ( j = 1; j <= 3; j++ )
{
for ( k = 1; k <= 4; k++ )
System.out.print( '*' );
System.out.println();
} // end inner for
System.out.println();
} // end outer for

6. Escreva um programa que leia um texto e:


a) conte o nº de palavras existentes no texto.
b) substitua todas as ocorrências de uma dada palavra por outra palavra.
c) Verifique se uma dada palavra existe no texto.

Write a program that reads a text and:


a) Counts the number of words in the text.
b) Replaces all occurrences of a given word with another word.
c) Check that a given word exists in the text.

Você também pode gostar