Last active
July 22, 2022 14:54
-
-
Save icarofreire/7e52b9b60caa0de7200893955e71b255 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 para verificar se uma lista de inteiros contém apenas números ímpares. | |
| 2) Escreva um programa para remover espaços em branco de uma string. | |
| 3) Escreva um programa para verificar se dois arrays contém os mesmos elementos. | |
| 4) Escreva um programa para somar todos os elementos de um array de inteiros. | |
| 5) 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(); | |
| } | |
| } | |
| 6) Existe um erro no seguinte trecho de código? Explique a razão. | |
| class Foo { | |
| void print(String s) { | |
| System.out.println(s); | |
| } | |
| void print(String s, int count) { | |
| while (count > 0) { | |
| System.out.println(s); | |
| count--; | |
| } | |
| } | |
| } | |
| 7) 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"); | |
| } | |
| 8) Qual o comportamento deste método? O que ele realiza? | |
| 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; | |
| } | |
| 9) Qual o comportamento deste código? O que ele realiza? | |
| 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); | |
| 10) Qual o comportamento deste código? O que ele realiza? | |
| 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(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment