Last active
November 14, 2023 11:47
-
-
Save icarofreire/d7b6a7e9b9fa2d260ed7c11292bed677 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Escreva um programa utilizando a sintaxe Java para verificar se uma lista de inteiros contém apenas números ímpares. | |
2) Escreva um programa utilizando a sintaxe Java para remover espaços em branco de uma string. | |
3) Escreva um programa utilizando a sintaxe Java para verificar se dois arrays contém os mesmos elementos. | |
4) Escreva um programa utilizando a sintaxe Java para somar todos os elementos de um array de inteiros. | |
5) Escreva um programa utilizando a sintaxe Java para inverter uma String. | |
6) Encontre o erro no seguinte trecho de código, e explique a razão. | |
interface I { | |
void foo(); | |
} | |
class A implements I{ | |
public void foo() {} | |
} | |
class B implements I{ | |
public void foo() {} | |
} | |
class C extends A, B { | |
public void bar() { | |
super.foo(); | |
} | |
} | |
7) Existe algum erro no seguinte trecho de código? Explique a razão, caso exista. | |
class Foo { | |
void print(String s) { | |
System.out.println(s); | |
} | |
void print(String s, int count) { | |
while (count > 0) { | |
System.out.println(s); | |
count--; | |
} | |
} | |
} | |
8) Qual será o valor booleano de "flag" para alcançar o bloco finally? | |
try { | |
if (flag) { | |
while (true) { | |
} | |
} else { | |
System.exit(1); | |
} | |
} finally { | |
System.out.println("In Finally"); | |
} | |
9) Em um array passado por parâmetro para o método, o que o método retorna no valor na variável b? | |
O que este método retorna? | |
private static int xxx(int[] array) { | |
int a = Integer.MIN_VALUE; | |
int b = Integer.MIN_VALUE; | |
for (int i : array) { | |
if (i > a) { | |
b = a; | |
a = i; | |
} else if (i > b) { | |
b = i; | |
} | |
} | |
return b; | |
} | |
10) O que contém o objeto charsCount no final do código? | |
String str1 = "abcdABCDabcd"; | |
char[] chars = str1.toCharArray(); | |
Map<Character, Integer> charsCount = new HashMap<>(); | |
for(char c : chars) { | |
if(charsCount.containsKey(c)) { | |
charsCount.put(c, charsCount.get(c)+1); | |
}else | |
charsCount.put(c, 1); | |
} | |
System.out.println(charsCount); | |
11) Qual o valor retornado no método xxx? | |
public class SimplePrograms { | |
public static void main(String[] args) { | |
String str = "123"; | |
System.out.println(xxx(str)); | |
} | |
public static String xxx(String in) { | |
if (in == null) | |
throw new IllegalArgumentException("Null is not valid input"); | |
StringBuilder out = new StringBuilder(); | |
char[] chars = in.toCharArray(); | |
for (int i = chars.length - 1; i >= 0; i--) | |
out.append(chars[i]); | |
return out.toString(); | |
} | |
} | |
12) No seguinte trecho de código, explique o resultado retornado ao objeto 'filtered1' e 'filtered2'. | |
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl"); | |
List<String> filtered1 = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList()); | |
System.out.println("A: " + filtered1); | |
String filtered2 = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(", ")); | |
System.out.println("B: " + filtered2); | |
13) No seguinte exemplo de código, qual mensagem será exibida pelo método main da classe FunctionalIntefaceMain? | |
public interface CustInterface{ | |
void print(); | |
default void printColor() | |
{ | |
System.out.println("Printing the color"); | |
} | |
} | |
public class FunctionalIntefaceMain { | |
public static void main(String[] args) | |
{ | |
FunctionalIntefaceMain pMain=new FunctionalIntefaceMain(); | |
pMain.printForm(() -> System.out.println("hello fun!")); | |
} | |
public void printForm(CustInterface c) | |
{ | |
c.print(); | |
} | |
} | |
14) No seguinte trecho de código, qual o resultado retornado/exibido a variável sum? | |
int sum = Arrays.stream(new int[]{1, 2, 3}) | |
.filter(i -> i >= 2) | |
.map(i -> i * 3) | |
.sum(); | |
System.out.println("B: " + sum); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment