├── src ├── streamselambdas │ ├── streams.txt │ ├── stramsecollections │ │ ├── desafioslambda │ │ │ ├── Desafio07.java │ │ │ ├── Desafio06.java │ │ │ ├── Desafio05.java │ │ │ ├── Desafio02.java │ │ │ ├── Desafio04.java │ │ │ ├── Desafio03.java │ │ │ └── Desafio01.java │ │ └── lambdaestreems │ │ │ ├── ExLambda07.java │ │ │ ├── ExLambda03.java │ │ │ ├── ExLambda01.java │ │ │ ├── ExLambda02.java │ │ │ ├── ExLambda08.java │ │ │ ├── ExLambda04.java │ │ │ ├── ExLambda05.java │ │ │ ├── ExLambda06.java │ │ │ ├── ExLambda09.java │ │ │ └── ExLambda10.java │ ├── primeiraaula │ │ ├── Aula01.java │ │ ├── Stream01.java │ │ └── Aula012.java │ ├── setimaaula │ │ └── Treino02.java │ ├── terceiraaula │ │ ├── Optional01.java │ │ └── Optional02.java │ ├── segundaaula │ │ ├── Aula022.java │ │ ├── Aula02.java │ │ └── Aula023.java │ ├── quartaaula │ │ ├── RecuceFuclion02.java │ │ ├── RecuceFuclion03.java │ │ └── RecuceFuclion01.java │ ├── sextaaula │ │ └── Treino01.java │ ├── oitavaaula │ │ └── Melhoria01.java │ └── quintaaula │ │ └── Collect01.java ├── operadorternario │ ├── OperadorTernario02.java │ └── OperadorTernario01.java ├── lacowhile │ ├── While07.java │ ├── While03.java │ ├── While04.java │ ├── While05.java │ ├── While08.java │ ├── While06.java │ ├── While01.java │ ├── While02.java │ ├── While12.java │ ├── While21.java │ ├── While15.java │ ├── While16.java │ ├── While13.java │ ├── While09.java │ ├── While14.java │ ├── While18.java │ ├── While10.java │ ├── While11.java │ ├── While25.java │ ├── While22.java │ ├── While19.java │ ├── While23.java │ ├── While24.java │ ├── While17.java │ ├── WhileBonus01.java │ ├── WhileBonus.java │ └── While20.java ├── POO │ ├── retangulo │ │ ├── Calcula.java │ │ ├── Retangulo.java │ │ └── Main03.java │ ├── carro │ │ ├── Main.java │ │ └── Carro.java │ ├── cachorro │ │ ├── Dog.java │ │ └── Main02.java │ ├── pessoa │ │ ├── Person.java │ │ └── Main.java │ └── DIO │ │ ├── contabancaria │ │ └── ContaBancaria.java │ │ └── contabancaria2 │ │ └── ContaBancaria2.java ├── ifelse │ ├── IfElse10.java │ ├── IfElse13.java │ ├── IfElse18.java │ ├── IfElse19.java │ ├── IfElse03.java │ ├── IfElse06.java │ ├── IfElse01.java │ ├── IfElse12.java │ ├── IfElse14.java │ ├── IfElse04.java │ ├── IfElse09.java │ ├── IfElse15.java │ ├── IfElse05.java │ ├── IfElse02.java │ ├── IfElse17.java │ ├── IfElse21.java │ ├── IfElse20.java │ ├── IfElse11.java │ ├── IfElse16.java │ ├── IfElse07.java │ └── IfElse08.java ├── campgemini │ └── sintax │ │ ├── Exercicio09.java │ │ ├── Exercicio07.java │ │ ├── Exercicio01.java │ │ ├── Exercicio08.java │ │ ├── Exercicio03.java │ │ ├── Exercicio05.java │ │ ├── Exercicio06.java │ │ ├── Exercicio02.java │ │ └── Exercicio04.java ├── switchcase │ ├── SwitchCase02.java │ └── SwitchCase01.java ├── metodos │ └── Metodo01.java ├── vetorArray │ ├── ParImpar.java │ └── PedraPapelTesoura.java └── classesesuasfuncionalidades │ ├── JoptionPene02.java │ └── JOptionPane01.java ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── bin ├── ifelse │ ├── IfElse01.class │ ├── IfElse02.class │ ├── IfElse03.class │ ├── IfElse04.class │ ├── IfElse05.class │ ├── IfElse06.class │ ├── IfElse07.class │ └── IfElse08.class ├── vetorArray │ └── ParImpar.class ├── switchcase │ ├── SwitchCase01.class │ └── SwitchCase02.class ├── operadorternario │ ├── OperadorTernario01.class │ └── OperadorTernario02.class └── classesesuasfuncionalidades │ └── JOptionPane01.class ├── .project ├── .classpath ├── README.md └── .gitignore /src/streamselambdas/streams.txt: -------------------------------------------------------------------------------- 1 | Eu 2 | Te 3 | Amo 4 | Bia -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /bin/ifelse/IfElse01.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse01.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse02.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse02.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse03.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse03.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse04.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse04.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse05.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse05.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse06.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse06.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse07.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse07.class -------------------------------------------------------------------------------- /bin/ifelse/IfElse08.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/ifelse/IfElse08.class -------------------------------------------------------------------------------- /bin/vetorArray/ParImpar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/vetorArray/ParImpar.class -------------------------------------------------------------------------------- /src/operadorternario/OperadorTernario02.java: -------------------------------------------------------------------------------- 1 | package operadorternario; 2 | 3 | public class OperadorTernario02 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /bin/switchcase/SwitchCase01.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/switchcase/SwitchCase01.class -------------------------------------------------------------------------------- /bin/switchcase/SwitchCase02.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/switchcase/SwitchCase02.class -------------------------------------------------------------------------------- /bin/operadorternario/OperadorTernario01.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/operadorternario/OperadorTernario01.class -------------------------------------------------------------------------------- /bin/operadorternario/OperadorTernario02.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/operadorternario/OperadorTernario02.class -------------------------------------------------------------------------------- /bin/classesesuasfuncionalidades/JOptionPane01.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatusMoura2/Estudos-Logica-Java/HEAD/bin/classesesuasfuncionalidades/JOptionPane01.class -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio07.java: -------------------------------------------------------------------------------- 1 | package desafioslambda; 2 | 3 | public class Desafio07 { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/lacowhile/While07.java: -------------------------------------------------------------------------------- 1 | 2 | package lacowhile; 3 | 4 | public class While07 { 5 | 6 | public static void main(String[] args) { 7 | int num = 1; 8 | 9 | while (num <= 100) { 10 | if (num % 2 == 0) { 11 | System.out.print(num + " "); 12 | } 13 | num++; 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/lacowhile/While03.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas Tabuadas de 3 números de entrada. 2 | 1° Número inicial, 2° Número final, 3° N° Tabela a ser calculado */ 3 | package lacowhile; 4 | 5 | public class While03 { 6 | 7 | public static void main(String[] args) { 8 | 9 | 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/lacowhile/While04.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas Tabuadas de 3 números de entrada. 2 | 1° Número inicial, 2° Número final, 3° N° Tabela a ser calculado na Ordem Reversa*/ 3 | package lacowhile; 4 | 5 | public class While04 { 6 | 7 | public static void main(String[] args) { 8 | 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/lacowhile/While05.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas as letras do alfabeto de A à Z.*/ 2 | package lacowhile; 3 | 4 | public class While05 { 5 | 6 | public static void main(String[] args) { 7 | char letra = 'a'; 8 | 9 | while (letra <= 'z') { 10 | System.out.print(letra+" "); 11 | letra++; 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/POO/retangulo/Calcula.java: -------------------------------------------------------------------------------- 1 | package POO.retangulo; 2 | 3 | public class Calcula { 4 | 5 | public static float calcularArea(Retangulo retangulo) { 6 | return retangulo.getLado01() * retangulo.getLado02(); 7 | } 8 | 9 | public static float calcularPerimetro(Retangulo retangulo) { 10 | return 2 * (retangulo.getLado01() + retangulo.getLado02()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/lacowhile/While08.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todos os números impares entre 1 a 100*/ 2 | package lacowhile; 3 | 4 | public class While08 { 5 | 6 | public static void main(String[] args) { 7 | 8 | int num = 1; 9 | 10 | while (num <= 100) { 11 | if (num % 2 == 1) { 12 | System.out.print(num + " "); 13 | } 14 | num++; 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/streamselambdas/primeiraaula/Aula01.java: -------------------------------------------------------------------------------- 1 | package primeiraaula; 2 | 3 | public class Aula01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | new Thread(new Runnable() { 8 | 9 | @Override 10 | public void run() { 11 | System.out.println("Olá mundo!"); 12 | } 13 | }).run(); 14 | 15 | new Thread(() -> System.out.println("Ola mundo 2")).run(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/lacowhile/While06.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas as letras 2 | * do alfabeto de Z á A, ou seja, na ordem Reversa.*/ 3 | 4 | package lacowhile; 5 | 6 | public class While06 { 7 | 8 | public static void main(String[] args) { 9 | char letra = 'z'; 10 | 11 | while (letra >= 'a') { 12 | System.out.print(letra+" "); 13 | letra--; 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Logica 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/streamselambdas/setimaaula/Treino02.java: -------------------------------------------------------------------------------- 1 | package setimaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Treino02 { 7 | public static void main(String[] args) { 8 | List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); 9 | 10 | list.stream().forEach(System.out::println);//reference method 11 | 12 | list.stream().forEach((n) -> System.out.println(n)); //not reference method 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/streamselambdas/terceiraaula/Optional01.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java 07 3 | */ 4 | package terceiraaula; 5 | 6 | public class Optional01 { 7 | 8 | public static void main(String[] args) { 9 | 10 | String num01 = "100"; 11 | 12 | Integer conversorInNumbers = conversorInNumbers(num01); 13 | 14 | System.out.println(conversorInNumbers); 15 | 16 | } 17 | 18 | public static Integer conversorInNumbers(String numStr) { 19 | return Integer.valueOf(numStr); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio06.java: -------------------------------------------------------------------------------- 1 | //Remoção de Duplicatas: Remova elementos duplicados de uma lista usando distinct. 2 | package desafioslambda; 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class Desafio06 { 8 | 9 | public static void main(String[] args) { 10 | 11 | List list = Arrays.asList(1,3,4,9,5, 2, 3, 4, 5, 6, 7, 8, 9, 10,8,9,6); 12 | 13 | list.stream().distinct().forEach(System.out::println); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/streamselambdas/primeiraaula/Stream01.java: -------------------------------------------------------------------------------- 1 | package primeiraaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Stream01 { 7 | 8 | public static void main(String[] args) { 9 | 10 | List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 11 | 12 | for (Integer integer : numbers) { 13 | System.out.println(integer); 14 | } 15 | 16 | 17 | numbers.stream() 18 | //filter 19 | .filter(e-> e % 2 == 0) 20 | //forEach 21 | .forEach(e -> System.out.println(e)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/lacowhile/While01.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todos os números naturais de 1 a N.*/ 2 | 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While01 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | int num1 = 1; 13 | System.out.println("Até quanto você quer contar: "); 14 | int contador = sc.nextInt(); 15 | 16 | while (num1 <= contador) { 17 | System.out.print(num1 + " "); 18 | num1++; 19 | 20 | } 21 | 22 | sc.close(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio05.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ordenação de Strings: Ordene uma lista de strings em ordem alfabética usando Streams. 3 | */ 4 | package desafioslambda; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class Desafio05 { 10 | 11 | public static void main(String[] args) { 12 | 13 | List list = Arrays.asList("a","y","s","d","f","g","h","j","z","k","j","h","g","h","j","j","h","g"); 14 | 15 | list.stream().sorted(String::compareTo).forEach(System.out::print); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio02.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Soma de Elementos: Calcule a soma de todos os elementos de uma lista de inteiros usando reduce 3 | */ 4 | package desafioslambda; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | public class Desafio02 { 11 | 12 | public static void main(String[] args) { 13 | 14 | List list = Arrays.asList(1,2,3,4,5,6,7,8,9,10); 15 | 16 | Optional soma = list.stream().reduce((n1, n2) -> n1 + n2); 17 | System.out.println(soma); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/POO/carro/Main.java: -------------------------------------------------------------------------------- 1 | /*Crie uma classe chamada Carro com os atributos marca, modelo e ano. 2 | *Implemente um construtor que receba esses três valores como parâmetros 3 | *e inicialize os atributos da classe. Crie também um método chamado exibirInformacoes() 4 | *que imprima os valores dos atributos na tela 5 | */ 6 | 7 | package POO.carro; 8 | 9 | public class Main { 10 | 11 | public static void main(String[] args) { 12 | Carro carro1 = new Carro("Ford", "Ka",2023); 13 | 14 | String infotmacoesCarro1 = carro1.exibirInformacoes(); 15 | 16 | System.out.println(infotmacoesCarro1); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/ifelse/IfElse10.java: -------------------------------------------------------------------------------- 1 | // Escreva um programa Java para inserir e exibir sua senha 2 | 3 | package ifelse; 4 | 5 | import java.util.Scanner; 6 | 7 | public class IfElse10 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | String senhaTrue = "12345"; 13 | 14 | System.out.print("Digite a sua senha: "); 15 | 16 | String senha = sc.nextLine(); 17 | 18 | if (senhaTrue.equals(senha)) { 19 | System.out.printf("Senha %s é verdadeira",senha); 20 | }else { 21 | System.out.printf("Senha %s é falsa",senha); 22 | } 23 | 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/streamselambdas/segundaaula/Aula022.java: -------------------------------------------------------------------------------- 1 | package segundaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class Aula022 { 7 | 8 | public static void main(String[] args) { 9 | 10 | List numbers = Arrays.asList(1, 1, 3, 4, 5, 8, 4, 5, 8, 3, 2, 5, 7, 6, 2, 8, 9, 2, 3, 4, 4, 5, 4, 6, 5, 11 | 6, 8, 9, 7, 5, 1, 4, 7); 12 | 13 | // Operações intermediarias ex:skip(),limit(), distinct(),filter 14 | numbers.stream() 15 | .filter(e -> e % 2 == 0). 16 | distinct(). 17 | skip(1). 18 | limit(40). 19 | forEach(e -> System.out.println(e));//operação final 20 | 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio04.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Contagem de Elementos: Conte quantos elementos em uma lista são maiores que 10. 3 | */ 4 | package desafioslambda; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | 10 | public class Desafio04 { 11 | 12 | public static void main(String[] args) { 13 | 14 | List list = Arrays.asList(1, 4, 8, 77, 80, 3, 4, 50, 13, 11, 10); 15 | 16 | Long maiorQ10 = list.stream() 17 | .filter(n -> n > 10) 18 | .collect(Collectors.counting()); 19 | 20 | System.out.println(maiorQ10); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/lacowhile/While02.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, 2 | * para imprimir todos os números naturais na ordem reversa.*/ 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While02 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num1 = 0; 14 | 15 | int contador; 16 | 17 | System.out.print("Qual numero você quer iniciar a contagem na ordem decresente: "); 18 | 19 | contador = sc.nextInt(); 20 | 21 | while (contador >= num1) { 22 | System.out.print(contador + " "); 23 | contador--; 24 | 25 | } 26 | sc.close(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/streamselambdas/primeiraaula/Aula012.java: -------------------------------------------------------------------------------- 1 | package primeiraaula; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | 6 | import javax.swing.JButton; 7 | 8 | public class Aula012 { 9 | public static void main(String[] args) { 10 | 11 | JButton button = new JButton(); 12 | 13 | button.addActionListener(new ActionListener() { 14 | 15 | @Override 16 | public void actionPerformed(ActionEvent e) { 17 | System.out.println("Ola Mundo!"); 18 | 19 | } 20 | }); 21 | 22 | JButton button2 = new JButton(); 23 | 24 | button2.addActionListener(e -> System.out.println("Ola Mundo!")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/desafioslambda/Desafio03.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Mapeamento de Strings: Dada uma lista de strings, converta todas para maiúsculas usando map. 3 | */ 4 | package desafioslambda; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | 10 | public class Desafio03 { 11 | 12 | public static void main(String[] args) { 13 | 14 | List family = Arrays.asList("Eu","Amo", "a","minha","família"); 15 | 16 | List family2 = family.stream().map(String::toUpperCase).collect(Collectors.toList()); 17 | 18 | System.out.println(family2); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio09.java: -------------------------------------------------------------------------------- 1 | /*Faça um algoritmo que receba um valor que foi depositado e exiba o valor com rendimento após um 2 | mês.Considere fixo o juro da poupança em 0,07% a. m; 3 | */ 4 | package campgemini.sintax; 5 | 6 | import java.util.Scanner; 7 | 8 | public class Exercicio09 { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | 13 | double deposito ; 14 | double juros; 15 | 16 | System.out.println("Qual o valor do deposito?"); 17 | 18 | deposito = sc.nextDouble(); 19 | juros = deposito * 0.0007; 20 | System.out.printf("O rendimento de %.2fR$ é de %.2fR$ ao mês.",deposito,juros); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/lacowhile/While12.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir o valor ASCII.*/ 2 | package lacowhile; 3 | 4 | import java.util.Scanner; 5 | 6 | public class While12 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | String ascii; 13 | char digito; 14 | int asciiInt; 15 | 16 | System.out.print("Digite caracteres: "); 17 | 18 | ascii = sc.nextLine(); 19 | 20 | int i =0; 21 | while(i numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 8 | Saída Esperada: 9 | 2 10 | 4 11 | 6 12 | 8 13 | 10 14 | */ 15 | package desafioslambda; 16 | 17 | import java.util.Arrays; 18 | import java.util.List; 19 | 20 | public class Desafio01 { 21 | 22 | public static void main(String[] args) { 23 | 24 | List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 25 | 26 | list.stream().filter((e) -> e % 2 == 0).forEach(System.out::println); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda07.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 7. Números Únicos 3 | *Dada uma lista de números com duplicatas, use Stream para remover as duplicatas e imprima os números únicos. 4 | 5 | *Exemplo de Entrada: 6 | *List numeros = Arrays.asList(1, 2, 2, 3, 4, 4, 5); 7 | Saída Esperada: 8 | 1 9 | 2 10 | 3 11 | 4 12 | 5 13 | */ 14 | package lambdaestreems; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | public class ExLambda07 { 20 | 21 | public static void main(String[] args) { 22 | 23 | List numbList = Arrays.asList(1, 2, 2, 3, 4, 4, 5); 24 | 25 | numbList.stream().distinct().forEach(e -> System.out.println(e)); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/lacowhile/While21.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir o número e 2 | * a soma de todos os inteiros entre 100 e 200 que são divisíveis por 9 3 | */ 4 | package lacowhile; 5 | 6 | public class While21 { 7 | 8 | public static void main(String[] args) { 9 | int num = 100; 10 | int soma = 0; 11 | 12 | while(num<=200) { 13 | while (num <= 200) { 14 | if (num % 9 == 0) { 15 | System.out.println("Números divisiveis por 9: "+num); 16 | soma += num; 17 | } 18 | num++; 19 | } 20 | 21 | System.out.println("A soma dos números divisíveis por 9 entre 100 e 200 é: " + soma); 22 | } 23 | } 24 | 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda03.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3. Transformação de Strings 3 | *Dada uma lista de strings, transforme todas as strings para maiúsculas e imprima-as. 4 | 5 | *Exemplo de Entrada: 6 | 7 | *List palavras = Arrays.asList("java", "lambda", "stream"); 8 | *Saída Esperada: 9 | 10 | *JAVA 11 | *LAMBDA 12 | *STREAM 13 | */ 14 | package lambdaestreems; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | public class ExLambda03 { 20 | 21 | public static void main(String[] args) { 22 | 23 | List words = Arrays.asList("Java", "Lambda", "stream"); 24 | 25 | words.stream().map(String::toUpperCase).forEachOrdered(System.out::println); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/lacowhile/While15.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para reverter 2 | os dígitos fornecidos como entrada.*/ 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While15 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | String digitos; 13 | String resultado = ""; 14 | char digitos2; 15 | 16 | System.out.print("Digite digitos para serem revertidos: "); 17 | digitos = sc.nextLine(); 18 | 19 | int i = digitos.length() - 1; 20 | while (i >= 0) { 21 | digitos2 = digitos.charAt(i); 22 | resultado += digitos2; 23 | i--; 24 | } 25 | 26 | System.out.printf("%s ao contrario é %s.",digitos,resultado); 27 | sc.close(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/lacowhile/While16.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para somar todos os dígitos*/ 2 | package lacowhile; 3 | 4 | import java.util.Scanner; 5 | 6 | public class While16 { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int cont; 12 | int resultado = 0; 13 | int digitos; 14 | 15 | System.out.println("Quantos digitos você ira digitar?"); 16 | cont = sc.nextInt(); 17 | 18 | int i =0; 19 | while (cont > 0) { 20 | System.out.print("digite o "+(i+1)+"° numero: "); 21 | i++; 22 | digitos =sc.nextInt(); 23 | resultado+=digitos; 24 | 25 | cont--; 26 | } 27 | 28 | System.out.println("A solma de todos os digitos é "+ resultado); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda01.java: -------------------------------------------------------------------------------- 1 | /** 2 | *Filtragem de Números Pares 3 | *Dada uma lista de números, use Stream para filtrar apenas os números pares e imprimi-los. 4 | 5 | *Exemplo de Entrada: 6 | 7 | *List numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 8 | *Saída Esperada: 9 | 10 | *2 11 | *4 12 | *6 13 | *8 14 | *10 15 | */ 16 | 17 | package lambdaestreems; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | public class ExLambda01 { 23 | 24 | public static void main(String[] args) { 25 | 26 | List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 27 | 28 | numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/ifelse/IfElse13.java: -------------------------------------------------------------------------------- 1 | /*Elabore um algoritmo que leia do teclado o sexo de uma pessoa. 2 | * Se o sexo digitado for M ou F, escrever na tela “Sexo válido!”. 3 | * Caso contrário, informar “Sexo inválido 4 | */ 5 | package ifelse; 6 | 7 | import java.util.Scanner; 8 | 9 | public class IfElse13 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | System.out.print("Didite um caractere correspondente a um sexo: "); 16 | char sexo = sc.next().charAt(0); 17 | 18 | if (sexo == 'M' || sexo == 'm' || sexo == 'F' || sexo == 'f') { 19 | System.out.println("Sexo valido!"); 20 | 21 | }else { 22 | System.out.println("Sexo invalido!"); 23 | } 24 | sc.close(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/lacowhile/While13.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para encontrar o fatorial de qualquer número.*/ 2 | package lacowhile; 3 | 4 | import java.util.Scanner; 5 | 6 | public class While13 { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int num; 12 | int fatorial = 1; 13 | 14 | System.out.print("Digite um numero para calcularmos o fatorial: "); 15 | num = sc.nextInt(); 16 | 17 | if (num < 0) { 18 | System.out.println("O numero precisa ser positivo"); 19 | 20 | } else { 21 | int i = 1; 22 | while (i <= num) { 23 | fatorial = fatorial * i; 24 | i++; 25 | } 26 | System.out.printf("O fatorial de %d é %d.", num, fatorial); 27 | } 28 | sc.close(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio07.java: -------------------------------------------------------------------------------- 1 | /*Leia uma temperatura em graus Celsius e apresentá-la convertida em graus Fahrenheit. Afórmula de 2 | conversão é:F=(9*C+160) / 5, sendo F a temperatura em Fahrenheit e C a temperatura emCelsius; */ 3 | package campgemini.sintax; 4 | 5 | import java.util.Scanner; 6 | 7 | public class Exercicio07 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int celsius; 13 | int fahrenheit; 14 | 15 | System.out.print("Qual temperatura será convertida?"); 16 | celsius = sc.nextInt(); 17 | 18 | fahrenheit = (9*celsius+160)/5; 19 | 20 | System.out.println(celsius+"° convertido para fharenheit fica "+fahrenheit+"°F"); 21 | 22 | sc.close(); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda02.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 2. Soma dos Quadrados 3 | *Dada uma lista de números, calcule a soma dos quadrados de todos os números. 4 | 5 | *Exemplo de Entrada: 6 | 7 | *List numeros = Arrays.asList(1, 2, 3, 4, 5); 8 | 9 | *Saída Esperada: 10 | *55 11 | */ 12 | 13 | package lambdaestreems; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | import javax.swing.JOptionPane; 19 | 20 | public class ExLambda02 { 21 | 22 | public static void main(String[] args) { 23 | 24 | List numbers = Arrays.asList(1, 2, 3, 4, 5); 25 | 26 | int soma = numbers.stream().map(n -> n * n).reduce(0, Integer::sum); 27 | 28 | JOptionPane.showMessageDialog(null, soma); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda08.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 8. Maior Número 3 | Dada uma lista de números, encontre o maior número usando Stream. 4 | 5 | Exemplo de Entrada: 6 | 7 | List numeros = Arrays.asList(10, 20, 30, 40, 50); 8 | Saída Esperada: 9 | 10 | 50 11 | */ 12 | package lambdaestreems; 13 | 14 | import java.util.Arrays; 15 | import java.util.Comparator; 16 | import java.util.List; 17 | import java.util.Optional; 18 | 19 | public class ExLambda08 { 20 | 21 | public static void main(String[] args) { 22 | 23 | List numbers = Arrays.asList(10, 20, 30, 40, 50); 24 | 25 | Optional numMax = numbers.stream().max(Comparator.naturalOrder()); 26 | 27 | System.out.println(numMax.get()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/streamselambdas/terceiraaula/Optional02.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java 08 3 | */ 4 | package terceiraaula; 5 | 6 | import java.util.Optional; 7 | 8 | public class Optional02 { 9 | 10 | public static void main(String[] args) { 11 | 12 | String num01 = "1a"; 13 | 14 | Optional number = conversorInNumbers(num01); 15 | 16 | number.ifPresent(n -> System.out.println(n)); 17 | number.orElse(5); 18 | 19 | System.out.println(number.isPresent()); 20 | System.out.println(number); 21 | 22 | } 23 | 24 | public static Optional conversorInNumbers(String numStr) { 25 | 26 | try { 27 | Integer valueOf = Integer.valueOf(numStr); 28 | return Optional.of(valueOf); 29 | } catch (Exception e) { 30 | return Optional.empty(); 31 | } 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda04.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 4. Contagem de Strings Longas 3 | *Dada uma lista de strings, conte quantas strings têm mais de 5 caracteres. 4 | 5 | *Exemplo de Entrada: 6 | 7 | 8 | *List palavras = Arrays.asList("java", "lambda", "stream", "api", "programming"); 9 | *Saída Esperada: 10 | 11 | *3 12 | */ 13 | package lambdaestreems; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | public class ExLambda04 { 19 | 20 | public static void main(String[] args) { 21 | 22 | List words = Arrays.asList("java", "lambda", "stream", "api", "programming"); 23 | 24 | long count = words.stream().filter(s -> s.length() > 5).count(); 25 | 26 | System.out.println(count); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/POO/cachorro/Dog.java: -------------------------------------------------------------------------------- 1 | package POO.cachorro; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Dog { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | private String nome; 10 | private String raca; 11 | 12 | public Dog(String nome, String raca) { 13 | this.nome = nome; 14 | this.raca = raca; 15 | } 16 | 17 | public String getNome() { 18 | return nome; 19 | } 20 | 21 | public void setNome(String nome) { 22 | nome = sc.nextLine(); 23 | this.nome = nome; 24 | } 25 | 26 | public String getRaca() { 27 | return raca; 28 | } 29 | 30 | public void setRaca(String raca) { 31 | raca = sc.nextLine(); 32 | this.raca = raca; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "[nome= " + nome + ", raca= " + raca + "]"; 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/lacowhile/While09.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para encontrar 2 | * a soma de todos os números entre 1 e N.*/ 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While09 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int num; 12 | long soma = 0; 13 | int loop = 1; 14 | System.out 15 | .print("Esse programa faz a soma de um até um número, em qual numero você quer terminar o contador? "); 16 | num = sc.nextInt(); 17 | 18 | if (num > 1) { 19 | while (loop <= num) { 20 | soma += loop; 21 | loop++; 22 | } 23 | System.out.printf("A soma dos números entre 1 e %d é %d",num,soma); 24 | } else { 25 | System.out.println("O numero tem que ser maior do que 1"); 26 | } 27 | sc.close(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/lacowhile/While14.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para encontrar o valor de um número elevado à potência de outro.*/ 2 | 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While14 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num = 0; 14 | int potencia; 15 | long resultado = 1l; 16 | 17 | System.out.print("Escolha um numero para ser elevado a uma potência: "); 18 | num = sc.nextInt(); 19 | 20 | System.out.print("Escolha a potência: "); 21 | potencia = sc.nextInt(); 22 | 23 | int i = 0; 24 | while (i < potencia) { 25 | resultado *= num; 26 | i++; 27 | 28 | } 29 | 30 | System.out.println(num + " elevado a " + potencia + "° potência é " + resultado + "."); 31 | sc.close(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/lacowhile/While18.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para calcular HCF(Algoritmo Euclidiano) de dois números de entrada.*/ 2 | package lacowhile; 3 | 4 | import java.util.Scanner; 5 | 6 | public class While18 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | System.out.print("Digite o primeiro número: "); 13 | int num1 = sc.nextInt(); 14 | 15 | System.out.print("Digite o segundo número: "); 16 | int num2 = sc.nextInt(); 17 | 18 | int mdc = calcularMDC(num1, num2); 19 | 20 | System.out.println("O MDC de " + num1 + " e " + num2 + " é: " + mdc); 21 | 22 | sc.close(); 23 | } 24 | 25 | public static int calcularMDC(int a, int b) { 26 | while (b != 0) { 27 | int temp = b; 28 | b = a % b; 29 | a = temp; 30 | } 31 | return a; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda05.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 5. Média de Números 3 | *Dada uma lista de números, calcule a média dos números. 4 | 5 | *Exemplo de Entrada: 6 | 7 | *List numeros = Arrays.asList(10, 20, 30, 40, 50); 8 | *Saída Esperada: 9 | 10 | *30.0 11 | */ 12 | package lambdaestreems; 13 | 14 | import java.util.Arrays; 15 | import java.util.List; 16 | import java.util.OptionalDouble; 17 | 18 | public class ExLambda05 { 19 | 20 | public static void main(String[] args) { 21 | 22 | List numbers = Arrays.asList(10, 20, 30, 40, 50); 23 | 24 | OptionalDouble average = numbers.stream().mapToInt(Integer::intValue).average(); 25 | 26 | Double averageValue = average.isPresent() ? average.getAsDouble() : 0; 27 | 28 | System.out.println(averageValue); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/ifelse/IfElse18.java: -------------------------------------------------------------------------------- 1 | package ifelse; 2 | 3 | import java.util.Scanner; 4 | 5 | public class IfElse18 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int maior = Integer.MIN_VALUE; 12 | int menor = Integer.MAX_VALUE; 13 | 14 | for (int i = 0; i < 5; i++) { 15 | System.out.print("Digite o " + (i + 1) + "º valor: "); 16 | int valor = sc.nextInt(); 17 | 18 | if (valor > maior) { 19 | maior = valor; 20 | } 21 | 22 | if (valor < menor) { 23 | menor = valor; 24 | } 25 | } 26 | 27 | System.out.println("O maior valor é: " + maior); 28 | System.out.println("O menor valor é: " + menor); 29 | 30 | sc.close(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda06.java: -------------------------------------------------------------------------------- 1 | /** 2 | *6. Concatenção de Strings 3 | *Dada uma lista de strings, concatene todas as strings em uma única string, separadas por vírgula. 4 | 5 | *Exemplo de Entrada: 6 | 7 | *List palavras = Arrays.asList("java", "lambda", "stream"); 8 | *Saída Esperada: 9 | *java,lambda,stream 10 | */ 11 | package lambdaestreems; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | import java.util.stream.Collectors; 16 | 17 | public class ExLambda06 { 18 | 19 | public static void main(String[] args) { 20 | 21 | List words = Arrays.asList("java", "lambda", "stream"); 22 | 23 | String worldsconcat = words.stream().map(e -> String.valueOf(e)).collect(Collectors.joining(", ")); 24 | 25 | System.out.println(worldsconcat); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=17 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=17 15 | -------------------------------------------------------------------------------- /src/streamselambdas/quartaaula/RecuceFuclion02.java: -------------------------------------------------------------------------------- 1 | package quartaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | public class RecuceFuclion02 { 8 | 9 | public static void main(String[] args) { 10 | 11 | String worlds = "Eu amo a minha familia!"; 12 | String[] split = worlds.split(" "); 13 | List list = Arrays.asList(split); 14 | 15 | Optional concat = list.stream().reduce((s1, s2) -> s1.concat(s2)); 16 | System.out.println(concat.get()); 17 | System.out.println("reduce concatenação"); 18 | 19 | System.out.println("-------------------------------------------------"); 20 | 21 | String concat2 = list.stream().reduce("",(s1, s2) -> s1.concat(s2)); 22 | System.out.println(concat2); 23 | System.out.println("reduce concatenação com identidade"); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio01.java: -------------------------------------------------------------------------------- 1 | /*Faça um algoritmo que receba dois números e exiba o resultado da sua soma;*/ 2 | 3 | package campgemini.sintax; 4 | 5 | import java.util.Scanner; 6 | 7 | public class Exercicio01 { 8 | 9 | static int soma(int num1, int num2) { 10 | return num1 + num2; 11 | } 12 | 13 | public static void main(String[] args) { 14 | 15 | Scanner sc = new Scanner(System.in); 16 | 17 | int num1, num2; 18 | 19 | int resultado; 20 | 21 | System.out.print("Digite o primeiro numero: "); 22 | num1 = sc.nextInt(); 23 | 24 | System.out.print("Digite o segundo numero: "); 25 | num2 = sc.nextInt(); 26 | 27 | resultado = soma(num1, num2); 28 | 29 | System.out.println(); 30 | System.out.print("O resultado da soma entre " + num1 + " e " + num2 + " é " + resultado); 31 | 32 | sc.close(); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/POO/pessoa/Person.java: -------------------------------------------------------------------------------- 1 | package POO.pessoa; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Person { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | private String name; 10 | private int idade; 11 | 12 | 13 | 14 | 15 | public Person(Scanner sc, String name, int idade) { 16 | this.name = name; 17 | this.idade = idade; 18 | } 19 | 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | 26 | public void setName(String name) { 27 | name = sc.nextLine(); 28 | this.name = name; 29 | } 30 | 31 | 32 | public int getIdade() { 33 | return idade; 34 | } 35 | 36 | 37 | public void setIdade(int idade) { 38 | idade = sc.nextInt(); 39 | this.idade = idade; 40 | } 41 | 42 | 43 | @Override 44 | public String toString() { 45 | return "Person [name=" + name + ", idade=" + idade + "]"; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio08.java: -------------------------------------------------------------------------------- 1 | /*Elabore um algoritmo que efetue a apresentação do valor da conversão em real (R$) de um valorlido em 2 | dólar (US$). O algoritmo deverá solicitar o valor da cotação do dólar e também aquantidade de dólares 3 | disponíveis com ousuário;*/ 4 | 5 | package campgemini.sintax; 6 | 7 | import javax.swing.JOptionPane; 8 | 9 | public class Exercicio08 { 10 | 11 | public static void main(String[] args) { 12 | 13 | String imput01 = JOptionPane.showInputDialog("Qual a cotação do dolar para hoje?"); 14 | String imput02 = JOptionPane.showInputDialog("Quanto você tem em dolar?"); 15 | 16 | double cotação = Double.parseDouble(imput01); 17 | double valorDolar = Double.parseDouble(imput02); 18 | 19 | JOptionPane.showMessageDialog(null, "O seu valor em real Brasileiro é de : " + (cotação * valorDolar) + "R$"); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/ifelse/IfElse19.java: -------------------------------------------------------------------------------- 1 | /*Faça um algoritmo que leia um número e mostre uma mensagem 2 | * indicando se este número é par ou ímpar e se é positivo ou negativo. 3 | */ 4 | package ifelse; 5 | 6 | import java.util.Scanner; 7 | 8 | public class IfElse19 { 9 | 10 | public static void main(String[] args) { 11 | 12 | Scanner sc = new Scanner(System.in); 13 | 14 | System.out.print("Escreva um numero inteiro: "); 15 | int num = sc.nextInt(); 16 | 17 | if (num < 0 && num % 2 == 0) { 18 | System.out.println(num + " é negativo e par"); 19 | 20 | } else if (num > 0 && num % 2 == 0) { 21 | System.out.println(num + " é positivo e par"); 22 | 23 | } else if (num > 0 && num % 2 == 1) { 24 | System.out.println(num + " é positivo e impar"); 25 | 26 | }else{ 27 | System.out.println(num + " é negativo e impar"); 28 | 29 | } 30 | 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/POO/carro/Carro.java: -------------------------------------------------------------------------------- 1 | package POO.carro; 2 | 3 | public class Carro { 4 | 5 | private String marca, modelo; 6 | private int ano; 7 | 8 | public Carro(String marca, String modelo, int ano) { 9 | super(); 10 | this.marca = marca; 11 | this.modelo = modelo; 12 | this.ano = ano; 13 | 14 | 15 | } 16 | 17 | public String getMarca() { 18 | return marca; 19 | } 20 | 21 | public void setMarca(String marca) { 22 | this.marca = marca; 23 | } 24 | 25 | public String getModelo() { 26 | return modelo; 27 | } 28 | 29 | public void setModelo(String modelo) { 30 | this.modelo = modelo; 31 | } 32 | 33 | public int getAno() { 34 | return ano; 35 | } 36 | 37 | public void setAno(int ano) { 38 | this.ano = ano; 39 | } 40 | 41 | public String exibirInformacoes() { 42 | return "Carro [marca=" + marca + ", modelo=" + modelo + ", ano=" + ano + "]"; 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/lacowhile/While10.java: -------------------------------------------------------------------------------- 1 | 2 | /*Escreva um programa Java, para encontrar a 3 | * soma de todos os números pares entre 1 e N.*/ 4 | package lacowhile; 5 | import java.util.Scanner; 6 | 7 | public class While10 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num; 14 | long soma = 0; 15 | int loop = 1; 16 | System.out.print( 17 | "Esse programa faz a soma de todos os numeros pares de um até o numero desejado, em qual numero você quer terminar o contador? "); 18 | num = sc.nextInt(); 19 | 20 | if (num > 1) { 21 | while (loop <= num) { 22 | if (loop % 2 == 0) 23 | soma += loop; 24 | loop++; 25 | 26 | } 27 | System.out.printf("A soma dos números pares entre 1 e %d é %d", num, soma); 28 | } else { 29 | System.out.println("O numero tem que ser maior do que 1"); 30 | } 31 | sc.close(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/lacowhile/While11.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para encontrar a 2 | * soma de todos os números impares entre 1 e N.*/ 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While11 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num; 14 | long soma = 0; 15 | int loop = 1; 16 | System.out.print( 17 | "Esse programa faz a soma de todos os numeros pares de um até o numero desejado, em qual numero você quer terminar o contador? "); 18 | num = sc.nextInt(); 19 | 20 | if (num > 1) { 21 | while (loop <= num) { 22 | if (loop % 2 == 1) 23 | soma += loop; 24 | loop++; 25 | 26 | } 27 | System.out.printf("A soma dos números impares entre 1 e %d é %d", num, soma); 28 | } else { 29 | System.out.println("O numero tem que ser maior do que 1"); 30 | } 31 | sc.close(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/streamselambdas/segundaaula/Aula02.java: -------------------------------------------------------------------------------- 1 | package segundaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | public class Aula02 { 8 | 9 | public static void main(String[] args) { 10 | 11 | List numbers = Arrays.asList(1, 1, 3, 4, 5, 8, 4, 5, 8, 3, 2, 5, 7, 6, 2, 8, 9, 2); 12 | 13 | //Java 4 14 | for (Iterator iterator = numbers.iterator(); iterator.hasNext();) { 15 | Integer integer = (Integer) iterator.next(); 16 | System.out.println(integer); 17 | } 18 | 19 | System.out.println("------------------------------------------------"); 20 | 21 | //Java 5 22 | for (Integer integer : numbers) { 23 | System.out.println(integer); 24 | } 25 | 26 | System.out.println("------------------------------------------------"); 27 | 28 | //Java 8 29 | numbers.stream().forEach(e -> System.out.println(e)); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda09.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 9. Agrupamento por Tamanho 3 | Dada uma lista de strings, agrupe-as pelo seu tamanho. 4 | 5 | Exemplo de Entrada: 6 | 7 | 8 | List palavras = Arrays.asList("java", "lambda", "stream", "api", "programming"); 9 | Saída Esperada: 10 | 11 | {3=[api], 4=[java], 6=[lambda, stream], 11=[programming]} 12 | */ 13 | package lambdaestreems; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | import java.util.Map; 18 | import java.util.stream.Collectors; 19 | 20 | public class ExLambda09 { 21 | 22 | public static void main(String[] args) { 23 | 24 | List words = Arrays.asList("java", "lambda", "stream", "api", "programming"); 25 | 26 | Map> newList2 = words.stream() 27 | .collect(Collectors.groupingBy(w -> w.length())); 28 | 29 | System.out.println(newList2); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/ifelse/IfElse03.java: -------------------------------------------------------------------------------- 1 | //Pegue três números do usuário e imprima o maior número. 2 | 3 | package ifelse; 4 | 5 | import java.util.Scanner; 6 | 7 | public class IfElse03 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | System.out.print("Digite o primeiro número: "); 12 | int num1 = sc.nextInt(); 13 | System.out.print("Digite o segundo número: "); 14 | int num2 = sc.nextInt(); 15 | System.out.print("Digite o terceiro número: "); 16 | int num3 = sc.nextInt(); 17 | 18 | if (num1 > num2 && num1 > num3) { 19 | System.out.println(num1 + " é o maior numero."); 20 | } else if (num2 > num1 && num2 > num3) { 21 | System.out.println(num2 + " é o maior numero"); 22 | } else if (num3 > num1 && num3 > num2) { 23 | System.out.println(num3 + " é o maior numero"); 24 | }else { 25 | System.out.println("isso não é um numeral inteiro"); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Exercícios de Lógica de Programação com a linguagem Java 2 | 3 | 4 | Bem-vindo ao meu repositório de exercícios de lógica de programação! 5 | Este repositório contém uma coleção de exercícios que eu resolvi como parte do meu aprendizado em lógica de programação com Java. 6 | 7 | ## Caso queira resolver os exercicios antes de conferi-los aqui: 8 | https://drive.google.com/drive/folders/1T3PZD66A_dhpG8rjscuwPYKGwGgxHxWt 9 | ## Organização 10 | 11 | - Os exercícios estão agrupados em pastas por categorias. 12 | - Cada pasta contém enunciados e soluções com a linguagem Java. 13 | 14 | ## Como Usar 15 | 16 | - Navegue pelas pastas para encontrar exercícios. 17 | - Leia os enunciados e confira as soluções propostas. 18 | - Contribuições são bem-vindas! Faça um fork, modifique e envie um pull request. 19 | 20 | ## Licença 21 | 22 | Este repositório está licenciado sob a Licença MIT. 23 | 24 | ## Contato 25 | 26 | matus.moura333x2@gmail.com 27 | -------------------------------------------------------------------------------- /src/streamselambdas/stramsecollections/lambdaestreems/ExLambda10.java: -------------------------------------------------------------------------------- 1 | /* 2 | 10. Ordenação Personalizada 3 | Dada uma lista de strings, ordene-as primeiro pelo tamanho e depois alfabeticamente. 4 | 5 | Exemplo de Entrada: 6 | 7 | List palavras = Arrays.asList("java", "lambda", "stream", "api", "programming"); 8 | Saída Esperada: 9 | 10 | api 11 | java 12 | lambda 13 | stream 14 | programming 15 | */ 16 | package lambdaestreems; 17 | import java.util.Arrays; 18 | import java.util.Comparator; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | public class ExLambda10 { 23 | 24 | public static void main(String[] args) { 25 | 26 | List words = Arrays.asList("java", "lambda", "stream", "api", "programming"); 27 | 28 | List newList = words.stream().sorted( Comparator.comparingInt(String::length)).collect(Collectors.toList()); 29 | 30 | newList.forEach(System.out::println); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/ifelse/IfElse06.java: -------------------------------------------------------------------------------- 1 | /* Escreva um programa Java que leia dois números de 2 | * ponto flutuante e teste se eles são iguais até três casas decimais*/ 3 | package ifelse; 4 | 5 | import java.text.DecimalFormat; 6 | import java.util.Scanner; 7 | 8 | public class IfElse06 { 9 | 10 | public static void main(String[] args) { 11 | 12 | Scanner sc = new Scanner(System.in); 13 | DecimalFormat df = new DecimalFormat("0.000"); 14 | 15 | double num1; 16 | double num2; 17 | 18 | System.out.print("Digite um numero decimal:"); 19 | num1 = sc.nextDouble(); 20 | System.out.print("Digite outro numero decimal:"); 21 | num2 = sc.nextDouble(); 22 | 23 | String numF1 = df.format(num1); 24 | String numF2 = df.format(num2); 25 | 26 | if (numF1.equals(numF2)) { 27 | System.out.println("Ambos são iguais até a terceira casa decimal!"); 28 | } else { 29 | System.out.println("Não são iguais até a terceira casa decimal!"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/operadorternario/OperadorTernario01.java: -------------------------------------------------------------------------------- 1 | /*Implemente um programa que recebe o valor total de uma compra e a 2 | * idade do cliente. Utilize o operador ternário para aplicar um desconto de 10% 3 | * se o cliente tiver 60 anos ou mais, e exiba o valor final a ser pago. 4 | */ 5 | package operadorternario; 6 | 7 | import java.util.Scanner; 8 | 9 | public class OperadorTernario01 { 10 | 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | System.out.print("Qual o valor do roduto?"); 14 | double precoProduto = sc.nextDouble(); 15 | System.out.print("Qual a sua idade?"); 16 | int idadeCliente = sc.nextInt(); 17 | 18 | String valorFinal = idadeCliente >= 60 19 | ? "O valor do produto é " + (precoProduto - (precoProduto * 0.1)) + "R$ com desconto de 10%" 20 | : "O valor do produto é " + precoProduto + " Você paga valor intrgral"; 21 | 22 | System.out.println(valorFinal); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/POO/pessoa/Main.java: -------------------------------------------------------------------------------- 1 | /* Escreva um programa Java para criar uma classe chamada "Pessoa" com um atributo 2 | * nome e idade. Crie duas instâncias da classe “Person”, 3 | * defina seus atributos usando o construtor e imprima seu nome e idade. 4 | */ 5 | 6 | package POO.pessoa; 7 | 8 | public class Main { 9 | 10 | public static void main(String[] args) { 11 | 12 | Person per1 = new Person(null, null, 0); 13 | 14 | Person per2 = new Person(null, null, 0); 15 | 16 | System.out.print("Digite o nome da pessoa 01: "); 17 | per1.setName(null); 18 | System.out.print("Digite a idade da pessoa 01: "); 19 | per1.setIdade(0); 20 | 21 | System.out.print("Digite o nome da pessoa 02: "); 22 | per2.setName(null); 23 | System.out.print("Digite a idade da pessoa 02: "); 24 | per2.setIdade(0); 25 | 26 | System.out.println(); 27 | 28 | System.out.println(per1.toString()); 29 | System.out.println(per2.toString()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/lacowhile/While25.java: -------------------------------------------------------------------------------- 1 | //Escreva um programa Java, para imprimir todos os números perfeitos de 1 a 10.000. 2 | 3 | package lacowhile; 4 | 5 | public class While25 { 6 | 7 | // Função para verificar se um número é perfeito 8 | static boolean ehNumeroPerfeito(int numero) { 9 | int somaDivisores = 0; 10 | int i = 1; 11 | 12 | while (i < numero) { 13 | if (numero % i == 0) { 14 | somaDivisores += i; 15 | } 16 | i++; 17 | } 18 | 19 | return somaDivisores == numero; 20 | } 21 | 22 | public static void main(String[] args) { 23 | System.out.println("Números perfeitos de 1 a 10000:"); 24 | 25 | int numero = 1; 26 | 27 | while (numero <= 10000) { 28 | if (ehNumeroPerfeito(numero)) { 29 | System.out.println(numero); 30 | } 31 | numero++; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/ifelse/IfElse01.java: -------------------------------------------------------------------------------- 1 | //Escreva um programa Java para obter um número do usuário e imprimir se é positivo ou negativo. 2 | 3 | package ifelse; 4 | 5 | import java.util.Scanner; 6 | 7 | public class IfElse01 { 8 | 9 | public static void main(String[] args) { 10 | 11 | //Objeto construido a partir da classe Scanner para obter variaveis a partir do teclado do usuario. 12 | Scanner sc = new Scanner(System.in); 13 | 14 | System.out.println("Digite um numero inteiro: "); 15 | int num = sc.nextInt(); 16 | 17 | //instruções if else para determinar se o numero é positivo ou negativo, se o digito é 0 ou até mesmo se é um digito numerico inteiro 18 | if(num < 0) { 19 | System.out.println("Número negativo"); 20 | }else if(num > 0){ 21 | System.out.println("Número positivo"); 22 | }else if(num == 0) { 23 | System.out.println("Número 0"); 24 | }else { 25 | System.out.println("Isso não é um numero"); 26 | } 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/ifelse/IfElse12.java: -------------------------------------------------------------------------------- 1 | /*Escrever um algoritmo que leia 2 | * dois valores inteiros distintos e informe qual é o maior 3 | */ 4 | 5 | package ifelse; 6 | 7 | import java.util.Scanner; 8 | 9 | public class IfElse12 { 10 | 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | 14 | System.out.println("Esse programa informa qual numero é o maior!"); 15 | 16 | System.out.print("Digite o primeiro número: "); 17 | int num1 = sc.nextInt(); 18 | 19 | System.out.print("Digite o segundo numero: "); 20 | int num2 = sc.nextInt(); 21 | 22 | if (num1 == num2) { 23 | System.out.println("Os números são iguais!"); 24 | 25 | } else if (num1 > num2) { 26 | System.out.printf("%d é maior que %d.", num1, num2); 27 | 28 | } else if (num1 < num2) { 29 | System.out.printf("%d é menor que %d.", num1, num2); 30 | 31 | }else { 32 | System.out.println("Digite numeros inteiros!"); 33 | } 34 | sc.close(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio03.java: -------------------------------------------------------------------------------- 1 | /*Escreva um algoritmo para determinar o consumo médio de um automóvel sendo fornecida a distância 2 | total percorrida pelo automóvel e o total de combustível gasto;*/ 3 | package campgemini.sintax; 4 | 5 | import java.util.Scanner; 6 | 7 | public class Exercicio03 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | double kmRodado,litrosConsumidos; 14 | 15 | System.out.print("Quantos Kms você dirigiu: "); 16 | kmRodado =sc.nextDouble(); 17 | 18 | System.out.println(); 19 | 20 | System.out.print("Quantos litros de combustivel foram consumidos: "); 21 | litrosConsumidos =sc.nextDouble(); 22 | 23 | if(kmRodado < litrosConsumidos) { 24 | System.out.println("Dados fornecidos invalidos"); 25 | }else { 26 | System.out.println("A medis de consumo do seu veiculo é de: "+(kmRodado/litrosConsumidos)+" por km!"); 27 | } 28 | sc.close(); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio05.java: -------------------------------------------------------------------------------- 1 | /*Escreva um algoritmo que leia o nome de um aluno e as notas das três provas que ele obteve no semestre. 2 | No finalinformar o nome do aluno e a sua média (aritmética);*/ 3 | package campgemini.sintax; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | public class Exercicio05 { 8 | 9 | public static void main(String[] args) { 10 | 11 | String nome = JOptionPane.showInputDialog("Qual o nome do aluno: "); 12 | String input01 = JOptionPane.showInputDialog("Qual a nota da primeira prova? "); 13 | String input02 = JOptionPane.showInputDialog("Qual a nota da primeira prova? "); 14 | String input03 = JOptionPane.showInputDialog("Qual a nota da primeira prova? "); 15 | 16 | double nota1 = Double.parseDouble(input02); 17 | double nota2 = Double.parseDouble(input02); 18 | double nota3 = Double.parseDouble(input02); 19 | 20 | JOptionPane.showMessageDialog(null, "Olá "+nome+" a sua media é "+((nota1+nota2+nota3)/3)); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/ifelse/IfElse14.java: -------------------------------------------------------------------------------- 1 | /*Elabore um algoritmo que leia dois números inteiros 2 | * e mostre o resultado da diferença do maior valor pelo menor 3 | */ 4 | 5 | package ifelse; 6 | 7 | import java.util.Scanner; 8 | 9 | public class IfElse14 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | System.out.print("Digite um número: "); 16 | int num1 = sc.nextInt(); 17 | 18 | System.out.print("Digite outo número: "); 19 | int num2 = sc.nextInt(); 20 | 21 | if (num1 > num2) { 22 | System.out.println("A diferença entre " + num1 + " e " + num2 + " é " + (num1 - num2)); 23 | 24 | } else if (num2 > num1) { 25 | System.out.println("A diferença entre " + num2 + " e " + num1 + " é " + (num2 - num1)); 26 | 27 | } else if (num1 == num2) { 28 | System.out.println("Não há diferença entre " + num1 + " e " + num2); 29 | 30 | }else { 31 | System.out.println("Por favor digite só números inteiros!"); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/lacowhile/While22.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para converter um número binário em 2 | * decimal sem usar (Array) – Tema que iremos abordar, após, Loops. 3 | */ 4 | package lacowhile; 5 | 6 | import java.util.Scanner; 7 | 8 | public class While22 { 9 | 10 | 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | System.out.print("Digite um número binário: "); 14 | String binary = sc.next(); 15 | 16 | int decimal = 0; 17 | int base = 1; 18 | int index = binary.length() - 1; 19 | 20 | while (index >= 0) { 21 | char bit = binary.charAt(index); 22 | 23 | if (bit == '1') { 24 | decimal += base; 25 | } 26 | 27 | base *= 2; 28 | index--; 29 | } 30 | 31 | System.out.println("O número decimal correspondente é: " + decimal); 32 | sc.close(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/ifelse/IfElse04.java: -------------------------------------------------------------------------------- 1 | /* Escreva um programa Java que leia um número de ponto flutuante e imprima "zero" se o número for zero. 2 | * Caso contrário, imprima "positivo" ou "negativo". Adicione "pequeno" 3 | * se o valor absoluto do número for menor que 1 ou "grande" se exceder 1.000.000*/ 4 | package ifelse; 5 | 6 | import java.util.Scanner; 7 | 8 | public class IfElse04 { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | System.out.print("Digite um numero: "); 13 | 14 | float num = sc.nextFloat(); 15 | 16 | if(num < 0 && num<1) { 17 | System.out.println(num+" é negativo e pequeno!"); 18 | }else if(num>0&& num>1000000) { 19 | System.out.println(num+" é positivo e grande!"); 20 | }else if(num == 0) { 21 | System.out.println("você digitou 0 numero pequeno"); 22 | }else if(num>0) { 23 | System.out.println(num+" é positivo!"); 24 | }else { 25 | System.out.println("Digite apenas um numero de ponto flutuante!"); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/switchcase/SwitchCase02.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa em Java para ler o gênero (M/F) 2 | *e imprimir o gênero correspondente usando uma instrução switch*/ 3 | package switchcase; 4 | 5 | import java.util.Scanner; 6 | 7 | public class SwitchCase02 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | char genero; 14 | var mM = "Masculino"; 15 | var fF = "Feminino"; 16 | 17 | System.out.print("Digite uma letra que corresponda a um genero M para masculino e F para feminino:"); 18 | 19 | genero = sc.next().charAt(0); 20 | 21 | switch (genero) { 22 | 23 | case 'M': 24 | System.out.println(mM); 25 | break; 26 | 27 | case 'm': 28 | System.out.println(mM); 29 | break; 30 | 31 | case 'f': 32 | System.out.println(fF); 33 | break; 34 | 35 | case 'F': 36 | System.out.println(fF); 37 | break; 38 | 39 | default: 40 | System.out.println("Esse caracter não representa um sexo!"); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/ifelse/IfElse09.java: -------------------------------------------------------------------------------- 1 | package ifelse; 2 | 3 | import java.util.Scanner; 4 | 5 | public class IfElse09 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Digite um ano: "); 12 | int ano = sc.nextInt(); 13 | 14 | if (isAnoBissexto(ano)) { 15 | System.out.println(ano + " é um ano bissexto."); 16 | } else { 17 | System.out.println(ano + " não é um ano bissexto."); 18 | } 19 | 20 | sc.close(); 21 | } 22 | 23 | /*Neste exemplo, o programa lê um ano do usuário e passa esse ano para o método isAnoBissexto, 24 | * que verifica se o ano é bissexto. O método verifica se o ano é divisível por 25 | * 4 e não é divisível por 100, ou se é divisível por 400. Se qualquer uma dessas 26 | * condições for atendida, o ano é considerado bissexto.*/ 27 | static boolean isAnoBissexto(int ano) { 28 | if ((ano % 4 == 0 && ano % 100 != 0) || (ano % 400 == 0)) { 29 | return true; 30 | } else { 31 | return false; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/ifelse/IfElse15.java: -------------------------------------------------------------------------------- 1 | /*Elabore um algoritmo a ler 4 notas de um aluno (de 1 a 10). 2 | * Após calcular a média das notas, apresentar a mensagem 3 | * “Aprovada” se o aluno tiver obtido média maior ou igual a 6, 4 | * caso contrário, apresentar “Reprovado”.*/ 5 | package ifelse; 6 | 7 | import java.util.Scanner; 8 | 9 | public class IfElse15 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | double notas[] = new double[4]; 16 | 17 | 18 | for (int i = 0; i < notas.length; i++) { 19 | System.out.print("Digite a " + (i + 1) + "° nota: "); 20 | notas[i] = sc.nextDouble(); 21 | 22 | if (notas[i] > 10 || notas[i] < 0) { 23 | System.out.println("Nota invalida reinicie o programa!"); 24 | break; 25 | } 26 | 27 | } 28 | double media = (notas[0] + notas[1] + notas[2] + notas[3]) / 4; 29 | if (media >= 6) { 30 | System.out.println("Aprovado(a)"); 31 | } else { 32 | System.out.println("Reprovado(a)"); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio06.java: -------------------------------------------------------------------------------- 1 | /*Leia dois valores para as variáveis A e B, e efetuar as trocas dos valores de forma que a variávelApasse a 2 | possuir ovalor da variável B e a variável B passe a possuir o valor da variável A.Apresentar osvalores 3 | trocados; */ 4 | package campgemini.sintax; 5 | 6 | import java.util.Scanner; 7 | 8 | public class Exercicio06 { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int a; 14 | int b; 15 | 16 | System.out.print("Digite um numero inteiro para a variavel a : "); 17 | a = sc.nextInt(); 18 | 19 | System.out.print("Digite outro numero inteiro para a variavel b: "); 20 | b = sc.nextInt(); 21 | 22 | System.out.printf("Você digitou %d para a e %d para b ", a, b); 23 | if (a != b) { 24 | int ab = a; 25 | a = a - a + b; 26 | b = b - b + ab; 27 | System.out.printf("agora a= %d e b= %d",a,b); 28 | } else { 29 | System.out.printf("as variaveis %d e %d são iguais", a, b); 30 | } 31 | sc.close(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/POO/retangulo/Retangulo.java: -------------------------------------------------------------------------------- 1 | package POO.retangulo; 2 | 3 | public class Retangulo { 4 | 5 | private float lado01; 6 | private float lado02; 7 | private float lado03; 8 | private float lado04; 9 | 10 | public Retangulo(float lado01, float lado02, float lado03, float lado04) { 11 | this.lado01 = lado01; 12 | this.lado02 = lado02; 13 | this.lado03 = lado03; 14 | this.lado04 = lado04; 15 | } 16 | 17 | public float getLado01() { 18 | return lado01; 19 | } 20 | 21 | public void setLado01(float lado01) { 22 | this.lado01 = lado01; 23 | } 24 | 25 | public float getLado02() { 26 | return lado02; 27 | } 28 | 29 | public void setLado02(float lado02) { 30 | this.lado02 = lado02; 31 | } 32 | 33 | public float getLado03() { 34 | return lado03; 35 | } 36 | 37 | public void setLado03(float lado03) { 38 | this.lado03 = lado03; 39 | } 40 | 41 | public float getLado04() { 42 | return lado04; 43 | } 44 | 45 | public void setLado04(float lado04) { 46 | this.lado04 = lado04; 47 | } 48 | 49 | 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio02.java: -------------------------------------------------------------------------------- 1 | /*Faça um algoritmo que receba dois números e ao final mostre a soma, subtração, multiplicação e a divisão 2 | dos dois números lidos; 3 | */ 4 | package campgemini.sintax; 5 | 6 | import javax.swing.JOptionPane; 7 | 8 | public class Exercicio02 { 9 | 10 | public static void main(String[] args) { 11 | 12 | String input01 = JOptionPane.showInputDialog("Digite o primeiro numero: "); 13 | String input02 = JOptionPane.showInputDialog("Digite o segundo numero: "); 14 | 15 | int num1 = Integer.parseInt(input01); 16 | int num2 = Integer.parseInt(input02); 17 | 18 | JOptionPane.showMessageDialog(null, "A soma entre " + num1 + " e " + num2 + " é " + (num1 + num2)); 19 | JOptionPane.showMessageDialog(null, "A subitração entre " + num1 + " e " + num2 + " é " + (num1 - num2)); 20 | JOptionPane.showMessageDialog(null, "A multiplicação entre " + num1 + " e " + num2 + " é " + (num1 * num2)); 21 | JOptionPane.showMessageDialog(null, 22 | "A divisão " + num1 + " e " + num2 + " é " + (num1 / num2) + " com resto " + (num1 % num2)); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/campgemini/sintax/Exercicio04.java: -------------------------------------------------------------------------------- 1 | /*Escreva um algoritmo que leia o nome de um vendedor, o seu salário fixo e o total de vendas efetuadas 2 | por ele no mês (em dinheiro). Sabendo que este vendedor ganha 15% de comissão sobre suas vendas 3 | efetuadas, informar o seu nome, o salário fixo e salário no final do mês;*/ 4 | 5 | package campgemini.sintax; 6 | 7 | import java.util.Scanner; 8 | 9 | public class Exercicio04 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | String nome; 16 | double salarioFixio, vendas; 17 | 18 | System.out.println("Qual o nome do vendedor? "); 19 | nome = sc.nextLine(); 20 | 21 | System.out.println("Qual o seu saario fixo? "); 22 | salarioFixio = sc.nextDouble(); 23 | 24 | System.out.println("Qunto " + nome + " vendeu? "); 25 | vendas = sc.nextDouble(); 26 | 27 | System.out.println("olá " + nome + " o seu salario fixo é de " + salarioFixio 28 | + "porem com a sua comissão o seu salario no final do mês será de " + (salarioFixio + (vendas * 0.15))); 29 | 30 | sc.close(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/streamselambdas/sextaaula/Treino01.java: -------------------------------------------------------------------------------- 1 | package sextaaula; 2 | 3 | import java.util.stream.IntStream; 4 | /* 5 | * Maneiras diferentes de escrever expressão lambda 6 | */ 7 | public class Treino01 { 8 | 9 | public static void main(String[] args) { 10 | 11 | //maneira comum 12 | IntStream.range(0, 11).filter(n -> n % 2 == 0).forEach(System.out::println); 13 | 14 | //quando temos que informar o tipo da variavel o parentese é obrigatorio 15 | IntStream.range(0, 11).filter((int n) -> n % 2 == 0).forEach(System.out::println); 16 | 17 | //quande temos mais de um argumento o parentese é obrigatorio 18 | IntStream.range(0, 11).filter(n -> n % 2 == 0).reduce((n1, n2) -> n1 + n2); 19 | 20 | //Quando eu não tenho nehum argumento parentese é obrigatorio 21 | Runnable runnable = () -> System.out.println("Trabalhar na fugioka é bom demais!"); 22 | runnable.run(); 23 | 24 | /** 25 | * Chaves 26 | */ 27 | // sempre que se coloca chaves é nescesario o uso do return 28 | IntStream.range(0, 11).filter((n) -> {return n % 2 == 0; }).forEach(System.out::println); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/ifelse/IfElse05.java: -------------------------------------------------------------------------------- 1 | /* Escreva um programa Java que mantenha um número do 2 | * usuário e gere um inteiro entre 1 e 7 e exiba o nome do dia da semana*/ 3 | package ifelse; 4 | 5 | import java.util.Scanner; 6 | 7 | public class IfElse05 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int numDia; 13 | 14 | System.out.println("Digite um número que represente um dia da semana: "); 15 | 16 | numDia = sc.nextInt(); 17 | 18 | if (numDia == 1) { 19 | System.out.println("Domingo"); 20 | } else if (numDia == 2) { 21 | System.out.println("Segunda-feira"); 22 | } else if (numDia == 3) { 23 | System.out.println("Terça-feira"); 24 | } else if (numDia == 4) { 25 | System.out.println("Quarta-feira"); 26 | } else if (numDia == 5) { 27 | System.out.println("Quinta-feira"); 28 | } else if (numDia == 6) { 29 | System.out.println("Sexta-feira"); 30 | } else if (numDia == 7) { 31 | System.out.println("Sabado"); 32 | } else{ 33 | System.out.println("Esse numero não representa um dia da semana!"); 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/switchcase/SwitchCase01.java: -------------------------------------------------------------------------------- 1 | 2 | //Escreva um programa em Java para ler um número de dia da semana e imprimir o nome do dia da semana usando a instrução switch 3 | 4 | package switchcase; 5 | 6 | import java.util.Scanner; 7 | 8 | public class SwitchCase01 { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int diaSemana; 13 | String dia; 14 | 15 | System.out.print("Digite um numero de um a 7 para obter um dia da semana: "); 16 | diaSemana = sc.nextInt(); 17 | 18 | switch (diaSemana) { 19 | case 1: 20 | dia = "Domingo"; 21 | break; 22 | case 2: 23 | dia = "Segunda-feira"; 24 | break; 25 | case 3: 26 | dia = "Terça-feira"; 27 | break; 28 | case 4: 29 | dia = "Quarta-feira"; 30 | break; 31 | case 5: 32 | dia = "Quinta-feira"; 33 | break; 34 | case 6: 35 | dia = "Sexta-feira"; 36 | break; 37 | case 7: 38 | dia = "Sabado"; 39 | break; 40 | default: 41 | dia = "Esse numero não representa um dia da semana";break; 42 | } 43 | 44 | System.out.printf("numero %d representa: %s.",diaSemana,dia); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/lacowhile/While19.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para inserir os números até o 2 | * usuário desejar e ao final devera exibir a contagem de 3 | * positivos, negativos e zeros inseridos. 4 | */ 5 | package lacowhile; 6 | 7 | import java.util.Scanner; 8 | 9 | public class While19 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | int cont, pos = 0, neg = 0, zer = 0, num; 15 | 16 | System.out.print("Quantos numeros você quer digitar: "); 17 | cont = sc.nextInt(); 18 | 19 | int i = 1; 20 | while (cont > 0) { 21 | System.out.print("Digite o " + i + "° numero: "); 22 | num = sc.nextInt(); 23 | i++; 24 | if (num > 0) { 25 | pos++; 26 | } else if (num < 0) { 27 | neg++; 28 | } else { 29 | zer++; 30 | } 31 | cont--; 32 | 33 | } 34 | System.out.print("A quantidade de numeros positivos é de: " + pos); 35 | System.out.println(); 36 | 37 | System.out.print("A quantidade de numeros negativos é de: " + neg); 38 | System.out.println(); 39 | 40 | System.out.print("A quantidade de zeros é de: " + zer); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/POO/cachorro/Main02.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java para criar uma classe chamada "Cachorro" 2 | * com um nome e um atributo de raça. Crie duas instâncias da classe "Dog", 3 | * defina seus atributos usando o construtor e modifique os atributos usando os 4 | * métodos setter e imprima os valores atualizados. 5 | * 6 | */ 7 | package POO.cachorro; 8 | 9 | public class Main02 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Dog dog01 = new Dog(null, null); 14 | Dog dog02 = new Dog(null, null); 15 | 16 | System.out.print("Digite o nome do cachorro 01: "); 17 | dog01.setNome(null); 18 | System.out.print("Digite a raça do cachorro 01: "); 19 | dog01.setRaca(null); 20 | 21 | System.out.print("Digite o nome do cachorro 02: "); 22 | dog02.setNome(null); 23 | System.out.print("Digite a raça do cachorro 02: "); 24 | dog02.setRaca(null); 25 | 26 | System.out.println("As informacões do cachorro 01, são:"); 27 | System.out.println(dog01.toString()); 28 | 29 | System.out.println("As informacões do cachorro 02, são:"); 30 | System.out.println(dog02.toString()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/lacowhile/While23.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para verificar se um número é um número forte ou não 2 | */ 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class While23 { 8 | 9 | static int fatorial(int n) { 10 | if (n == 0 || n == 1) { 11 | return 1; 12 | } else { 13 | return n * fatorial(n - 1); 14 | } 15 | } 16 | 17 | // Função para verificar se um número é forte 18 | static boolean ehNumeroForte(int numero) { 19 | int original = numero; 20 | int somaFatoriais = 0; 21 | 22 | while (numero > 0) { 23 | int digito = numero % 10; 24 | somaFatoriais += fatorial(digito); 25 | numero /= 10; 26 | } 27 | 28 | return somaFatoriais == original; 29 | } 30 | 31 | public static void main(String[] args) { 32 | 33 | Scanner sc = new Scanner(System.in); 34 | 35 | System.out.print("Digite um numero para sabermos se é forte ou não:"); 36 | 37 | int numero = sc.nextInt(); 38 | 39 | if (ehNumeroForte(numero)) { 40 | System.out.println(numero + " é um número forte."); 41 | } else { 42 | System.out.println(numero + " não é um número forte."); 43 | } 44 | 45 | sc.close(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/metodos/Metodo01.java: -------------------------------------------------------------------------------- 1 | /*Crie um método que recebe uma string como parâmetro 2 | * e retorna true se a string for um palíndromo 3 | * (ou seja, lê-se da mesma forma de trás para frente) 4 | * e false caso contrário.*/ 5 | package metodos; 6 | 7 | import java.util.Scanner; 8 | 9 | public class Metodo01 { 10 | 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | 14 | System.out.print("Digite uma palavra: "); 15 | String palavra = sc.nextLine(); 16 | 17 | if (isPalindromo(palavra)) { 18 | System.out.println(palavra + " é um palíndromo!"); 19 | } else { 20 | System.out.println(palavra + " não é um palíndromo."); 21 | } 22 | 23 | sc.close(); 24 | } 25 | 26 | static boolean isPalindromo(String palavra) { 27 | int tamanho = palavra.length(); 28 | 29 | for (int i = 0; i < tamanho / 2; i++) { 30 | if (palavra.charAt(i) != palavra.charAt(tamanho - 1 - i)) { 31 | return false; 32 | } 33 | } 34 | 35 | return true; 36 | } 37 | } 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/streamselambdas/quartaaula/RecuceFuclion03.java: -------------------------------------------------------------------------------- 1 | package quartaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.DoubleStream; 6 | 7 | public class RecuceFuclion03 { 8 | 9 | public static void main(String[] args) { 10 | 11 | List list = Arrays.asList(1, 2, 3, 4, 5, 6); 12 | 13 | // reduce soma com identidade 14 | Integer reduce = list.stream().reduce(0, (n1, n2) -> n1 + n2); 15 | System.out.print(reduce); 16 | System.out.println(" reduce soma com identidade"); 17 | 18 | System.out.println("-------------------------------------------------"); 19 | 20 | Integer reduce2 = list.stream().reduce(1, (n1, n2) -> n1 * n2); 21 | System.out.print(reduce2); 22 | System.out.println(" reduce multiplicação com identidade"); 23 | 24 | System.out.println("-------------------------------------------------"); 25 | 26 | // reduce - menor valor 27 | double minvalue = DoubleStream.of(1.5, 2.8, 1.6, 4.0, 5.1, 3.0).reduce(Double.POSITIVE_INFINITY, 28 | (d1, d2) -> Math.min(d1, d2)); 29 | System.out.println(minvalue); 30 | 31 | System.out.println("-------------------------------------------------"); 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/lacowhile/While24.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todos os números fortes de 1 a 100.000. 2 | * 3 | */ 4 | 5 | package lacowhile; 6 | 7 | 8 | public class While24 { 9 | 10 | // Função para calcular o fatorial de um número 11 | static int fatorial(int n) { 12 | if (n == 0 || n == 1) { 13 | return 1; 14 | } else { 15 | return n * fatorial(n - 1); 16 | } 17 | } 18 | 19 | // Função para verificar se um número é forte 20 | static boolean ehNumeroForte(int numero) { 21 | int original = numero; 22 | int somaFatoriais = 0; 23 | 24 | while (numero > 0) { 25 | int digito = numero % 10; 26 | somaFatoriais += fatorial(digito); 27 | numero /= 10; 28 | } 29 | 30 | return somaFatoriais == original; 31 | } 32 | 33 | public static void main(String[] args) { 34 | 35 | System.out.println("Números fortes de 1 a 100000:"); 36 | 37 | int numero = 1; 38 | 39 | while (numero <= 100000) { 40 | if (ehNumeroForte(numero)) { 41 | System.out.println(numero); 42 | } 43 | numero++; 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/ifelse/IfElse02.java: -------------------------------------------------------------------------------- 1 | /*. Escreva um programa Java para resolver equações quadráticas (use if, else if e else). Ir para o editor 2 | Dados de teste 3 | Entrada a: 1 4 | Entrada b: 5 5 | Entrada c: 1 6 | Saída Esperada: 7 | As raízes são -0,20871215252208009 e -4,7912878474779195 8 | */ 9 | package ifelse; 10 | 11 | import java.util.Scanner; 12 | 13 | public class IfElse02 { 14 | 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | 18 | double a; 19 | double b; 20 | double c; 21 | 22 | double delta; 23 | 24 | System.out.print("Entre com o valor de a: "); 25 | a = sc.nextDouble(); 26 | 27 | System.out.print("Entre com o valor de b: "); 28 | b = sc.nextDouble(); 29 | 30 | System.out.print("Entre com o valor de c: "); 31 | c = sc.nextDouble(); 32 | 33 | delta = b * b - 4 * a * c; 34 | 35 | if (delta > 0) { 36 | double x1 = (-b + Math.sqrt(delta)) / (2 * a); 37 | double x2 = (-b - Math.sqrt(delta)) / (2 * a); 38 | System.out.println("As raízes são " + x1 + " e " + x2); 39 | } else if (delta == 0) { 40 | double x = -b / (2 * a); 41 | System.out.println("A raiz dupla é " + x); 42 | } else { 43 | System.out.println("A equação não possui raízes reais."); 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/ifelse/IfElse17.java: -------------------------------------------------------------------------------- 1 | /*A escola “APRENDER” faz o pagamento de seus professores por hora/aula. Faça um algoritmo que 2 | calcule e exiba o salário de um professor. Sabe-se que o valor da hora/aula segue a tabela abaixo: 3 | Professor Nível 1 R$12,00 por hora/aula Professor Nível 2 R$17,00 por hora/aula Professor Nível 4 | 3 R$25,00 por hora/aula*/ 5 | package ifelse; 6 | 7 | import java.util.Scanner; 8 | 9 | public class IfElse17 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | double horaAula = 0; 16 | 17 | System.out.print("Qual o seu nivel Professor? 1 - 2 - 3: "); 18 | int nivel = sc.nextInt(); 19 | 20 | System.out.print("Quantas horas você ensinou na escoloa Aprender esse mês? "); 21 | double horasLecionadas = sc.nextDouble(); 22 | if (nivel == 1) { 23 | horaAula = 12; 24 | System.out.println("Você tem " + (horaAula * horasLecionadas) + "R$ a receber."); 25 | 26 | } else if (nivel == 2) { 27 | horaAula = 17; 28 | System.out.println("Você tem " + (horaAula * horasLecionadas) + "R$ a receber."); 29 | 30 | } else if (nivel == 3) { 31 | horaAula = 25; 32 | System.out.println("Você tem " + (horaAula * horasLecionadas) + "R$ a receber."); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/lacowhile/While17.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para verificar se um determinado número é primo ou não.*/ 2 | package lacowhile; 3 | 4 | import java.util.Scanner; 5 | 6 | public class While17 { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Digite um número inteiro positivo: "); 12 | int numero = sc.nextInt(); 13 | 14 | boolean ehPrimo = ehPrimo(numero); 15 | 16 | if (ehPrimo) { 17 | System.out.println(numero + " é um número primo."); 18 | } else { 19 | System.out.println(numero + " não é um número primo."); 20 | } 21 | 22 | sc.close(); 23 | } 24 | 25 | 26 | public static boolean ehPrimo(int numero) { 27 | if (numero <= 1) { 28 | return false; 29 | } 30 | if (numero <= 3) { 31 | return true; 32 | } 33 | if (numero % 2 == 0 || numero % 3 == 0) { 34 | return false; 35 | } 36 | 37 | int i = 5; 38 | while (i * i <= numero) { 39 | if (numero % i == 0 || numero % (i + 2) == 0) { 40 | return false; 41 | } 42 | i += 6; 43 | } 44 | 45 | return true; 46 | } 47 | } -------------------------------------------------------------------------------- /src/ifelse/IfElse21.java: -------------------------------------------------------------------------------- 1 | /*Construa um algoritmo que calcule o peso ideal de uma pessoa. 2 | * Dados de entrada: altura e sexo. 3 | * Fórmulas para cálculo do peso: 4 | * peso ideal de homem = (72,7 * altura) - 58 5 | * peso ideal da mulher = (62,1 * altura) - 44,7 6 | */ 7 | package ifelse; 8 | 9 | import java.util.Scanner; 10 | 11 | public class IfElse21 { 12 | 13 | public static void main(String[] args) { 14 | 15 | Scanner sc = new Scanner(System.in); 16 | 17 | String sexo; 18 | double peso; 19 | double altura; 20 | 21 | System.out.print("Qual o seu sexo? M p/masculino F p/feminino: "); 22 | sexo = sc.nextLine().trim().toUpperCase(); 23 | 24 | System.out.print("Digite o seu peso: "); 25 | peso = sc.nextDouble(); 26 | 27 | System.out.print("Digite a sua altura: "); 28 | altura = sc.nextDouble(); 29 | 30 | if(sexo.equals("M")) { 31 | if(altura*peso <= 58) { 32 | System.out.println("Peso ideal!"); 33 | }else { 34 | System.out.println("Fora de forma!"); 35 | } 36 | }else if(sexo.equals("F")){ 37 | if(altura*peso <= 44.7) { 38 | System.out.println("Peso ideal!"); 39 | }else { 40 | System.out.println("Fora de forma!"); 41 | } 42 | }else { 43 | System.out.println("Não é um sexo valido!"); 44 | } 45 | 46 | sc.close(); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/ifelse/IfElse20.java: -------------------------------------------------------------------------------- 1 | /* Dados três valores X, Y e Z, 2 | * verificar se eles podem ser os comprimentos 3 | * dos lados de um triângulo e, se forem verificar se é um triângulo equilátero, 4 | * isósceles ou escalenos. Se eles não formarem um triângulo, escrever a mensagem. 5 | * Considere as seguintes propriedades: •O comprimento de cada lado em um triângulo é 6 | * menor que a soma dos outros dois lados; •Equiláteros: tem os comprimentos dos três 7 | * lados iguais; •Isósceles: tem os comprimentos de dois lados iguais; •escaleno: 8 | * tem os comprimentos dos três lados diferentes. 9 | */ 10 | 11 | package ifelse; 12 | 13 | import java.util.Scanner; 14 | 15 | public class IfElse20 { 16 | 17 | public static void main(String[] args) { 18 | 19 | Scanner sc = new Scanner(System.in); 20 | 21 | int maior = Integer.MIN_VALUE; 22 | int x, y, z, valor = 0; 23 | 24 | System.out.println("Digite tres valores"); 25 | System.out.print("Valor X: "); 26 | x = sc.nextInt(); 27 | 28 | System.out.print("Valor Y: "); 29 | y = sc.nextInt(); 30 | 31 | System.out.print("Valor Z: "); 32 | z = sc.nextInt(); 33 | 34 | if (x > maior) { 35 | maior = valor; 36 | } else if (y > maior) { 37 | maior = valor; 38 | 39 | } else if (z > maior) { 40 | maior = valor; 41 | } 42 | 43 | System.out.println(valor); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/lacowhile/WhileBonus01.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas Tabuadas de 3 números de entrada.*/ 2 | 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class WhileBonus01 { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num1; 14 | int num2; 15 | int num3; 16 | int resultado1; 17 | int resultado2; 18 | int resultado3; 19 | 20 | System.out.println("Quais numeros você quer a tabuada?"); 21 | System.out.print("Digite o primeiro numero: "); 22 | num1 = sc.nextInt(); 23 | 24 | System.out.print("Digite o segundo numero: "); 25 | num2 = sc.nextInt(); 26 | 27 | System.out.print("Digite o terceiro numero: "); 28 | num3 = sc.nextInt(); 29 | 30 | System.out.println(); 31 | int i = 1; 32 | while (i <= 10) { 33 | resultado1 = num1 * i; 34 | 35 | System.out.println(num1 + " x " + i + " = " + resultado1); 36 | i++; 37 | 38 | } 39 | 40 | System.out.println(); 41 | i = 1; 42 | while (i <= 10) { 43 | resultado2 = num2 * i; 44 | 45 | System.out.println(num2 + " x " + i + " = " + resultado2); 46 | 47 | i++; 48 | 49 | } 50 | 51 | System.out.println(); 52 | i = 1; 53 | while (i <= 10) { 54 | resultado3 = num3 * i; 55 | 56 | System.out.println(num3 + " x " + i + " = " + resultado3); 57 | 58 | i++; 59 | 60 | } 61 | sc.close(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/ifelse/IfElse11.java: -------------------------------------------------------------------------------- 1 | /*Escrever um algoritmo que leia o nome e as três notas obtidas por um aluno 2 | * durante o semestre. Calcular a sua média (aritmética), informar o nome e 3 | * sua menção aprovado (media >= 7), Reprovado (media <= 5) e Recuperação 4 | * (media entre 5.1 a 6.9). 5 | */ 6 | package ifelse; 7 | 8 | import java.util.Scanner; 9 | 10 | public class IfElse11 { 11 | 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | 15 | String nome; 16 | 17 | double nota01; 18 | double nota02; 19 | double nota03; 20 | 21 | double media; 22 | 23 | System.out.print("Escreva o seu nome: "); 24 | nome = sc.nextLine(); 25 | 26 | System.out.println("Qual a sua primeira nota?"); 27 | nota01 = sc.nextDouble(); 28 | 29 | System.out.println("Qual a sua segunda nota?"); 30 | nota02 = sc.nextDouble(); 31 | 32 | System.out.println("Qual a sua terceira nota?"); 33 | nota03 = sc.nextDouble(); 34 | 35 | media = (nota01 + nota02 + nota03) / 3; 36 | 37 | if (media <= 5) { 38 | System.out.printf("%s você foi reprovado!", nome); 39 | 40 | } else if (media > 5 && media < 6) { 41 | System.out.printf("%s você ficou de recuperação!", nome); 42 | 43 | } else if (media >= 7) { 44 | System.out.printf("%s você foi aprovado(a)", nome); 45 | }else { 46 | System.out.println(" isso não é uma media valida!"); 47 | } 48 | sc.close(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/lacowhile/WhileBonus.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para imprimir todas Tabuadas de 3 números de entrada na Ordem Reversa.*/ 2 | 3 | package lacowhile; 4 | 5 | import java.util.Scanner; 6 | 7 | public class WhileBonus { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | 13 | int num1; 14 | int num2; 15 | int num3; 16 | int resultado1; 17 | int resultado2; 18 | int resultado3; 19 | 20 | System.out.println("Quais numeros você quer a tabuada na ordrm reversa?"); 21 | System.out.print("Digite o primeiro numero: "); 22 | num1 = sc.nextInt(); 23 | 24 | System.out.print("Digite o segundo numero: "); 25 | num2 = sc.nextInt(); 26 | 27 | System.out.print("Digite o terceiro numero: "); 28 | num3 = sc.nextInt(); 29 | 30 | System.out.println(); 31 | int i = 10; 32 | while (i >= 1) { 33 | resultado1 = num1 * i; 34 | 35 | System.out.println(num1 + " x " + i + " = " + resultado1); 36 | i--; 37 | 38 | } 39 | 40 | System.out.println(); 41 | i = 10; 42 | while (i >= 1) { 43 | resultado2 = num2 * i; 44 | 45 | System.out.println(num2 + " x " + i + " = " + resultado2); 46 | 47 | i--; 48 | 49 | } 50 | 51 | System.out.println(); 52 | i = 10; 53 | while (i >= 1) { 54 | resultado3 = num3 * i; 55 | 56 | System.out.println(num3 + " x " + i + " = " + resultado3); 57 | 58 | i--; 59 | 60 | } 61 | sc.close(); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/lacowhile/While20.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java, para inserir 2 | * os números até que o usuário queira e 3 | * ao final o programa deverá exibir os maiores 4 | * e menores números digitados. 5 | */ 6 | package lacowhile; 7 | 8 | import java.util.Scanner; 9 | 10 | public class While20 { 11 | 12 | public static void main(String[] args) { 13 | Scanner scanner = new Scanner(System.in); 14 | 15 | int maior = Integer.MIN_VALUE; // Inicialize com o menor valor possível 16 | int menor = Integer.MAX_VALUE; // Inicialize com o maior valor possível 17 | 18 | boolean continuar = true; 19 | 20 | while (continuar) { 21 | System.out.print("Digite um número (ou digite 0 para encerrar): "); 22 | int numero = scanner.nextInt(); 23 | 24 | if (numero == 0) { 25 | continuar = false; // Encerra o loop 26 | } else { 27 | if (numero > maior) { 28 | maior = numero; 29 | } 30 | if (numero < menor) { 31 | menor = numero; 32 | } 33 | } 34 | } 35 | 36 | if (maior != Integer.MIN_VALUE) { 37 | System.out.println("O maior número digitado é: " + maior); 38 | System.out.println("O menor número digitado é: " + menor); 39 | } else { 40 | System.out.println("Nenhum número foi digitado."); 41 | } 42 | 43 | scanner.close(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/streamselambdas/quartaaula/RecuceFuclion01.java: -------------------------------------------------------------------------------- 1 | package quartaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | public class RecuceFuclion01 { 8 | 9 | public static void main(String[] args) { 10 | 11 | List list = Arrays.asList(1, 2, 3, 4, 5, 6); 12 | 13 | //imprime a lista 14 | list.stream().forEach(System.out::print); 15 | 16 | System.out.println("\n-------------------------------------------------"); 17 | 18 | // reduce soma 19 | Optional reduce = list.stream().reduce((n1, n2) -> n1 + n2); 20 | System.out.print(reduce.get()); 21 | System.out.println(" reduce soma"); 22 | 23 | System.out.println("-------------------------------------------------"); 24 | 25 | // reduce multiplicação 26 | Optional reduce2 = list.stream().reduce((n1, n2) -> n1 * n2); 27 | 28 | System.out.print(reduce2.get()); 29 | System.out.println(" reduce multiplicação"); 30 | 31 | System.out.println("-------------------------------------------------"); 32 | 33 | //reduce divisão 34 | Optional reduce3 = list.stream().reduce((n1, n2) -> n1 / n2); 35 | 36 | System.out.print(reduce3.get()); 37 | System.out.println(" reduce divisão"); 38 | 39 | System.out.println("-------------------------------------------------"); 40 | 41 | //reduce subitração 42 | Optional reduce4 = list.stream().reduce((n1, n2) -> n1 - n2); 43 | 44 | System.out.print(reduce4.get()); 45 | System.out.println(" reduce subitração"); 46 | 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/ifelse/IfElse16.java: -------------------------------------------------------------------------------- 1 | /*Altere o algoritmo anterior para que seja lido do teclado, 2 | * além das notas, o sexo do aluno (M ou F). Se for masculino, 3 | * o resultado deverá ser precedido de “Caro aluno, seu resultado é: “. 4 | * Se for feminino, o resultado deverá ser precedido de “Cara aluna, seu resultado é: “. 5 | */ 6 | package ifelse; 7 | 8 | import java.util.Scanner; 9 | 10 | public class IfElse16 { 11 | 12 | public static void main(String[] args) { 13 | 14 | Scanner sc = new Scanner(System.in); 15 | 16 | double notas[] = new double[4]; 17 | 18 | System.out.print("Qual o seu sexo, digite M para masculino e F para feminino: "); 19 | char sex = sc.next().charAt(0); 20 | 21 | for (int i = 0; i < notas.length; i++) { 22 | System.out.print("Digite a " + (i + 1) + "° nota: "); 23 | notas[i] = sc.nextDouble(); 24 | 25 | if (notas[i] > 10 || notas[i] < 0) { 26 | System.out.println("Nota invalida reinicie o programa!"); 27 | break; 28 | } 29 | 30 | } 31 | double media = (notas[0] + notas[1] + notas[2] + notas[3]) / 4; 32 | if (media >= 6) { 33 | if (Character.toUpperCase(sex) == 'M') { 34 | System.out.println("Caro aluno, seu resultado é: aprovado"); 35 | } else if (Character.toUpperCase(sex) == 'F') { 36 | System.out.println("Cara aluna, seu resultado é: aprovada"); 37 | } 38 | } else { 39 | if (Character.toUpperCase(sex) == 'M') { 40 | System.out.println("Caro aluno, seu resultado é: reprovado"); 41 | } else if (Character.toUpperCase(sex) == 'F') { 42 | System.out.println("Cara aluna, seu resultado é: reprovada"); 43 | } 44 | } 45 | 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/vetorArray/ParImpar.java: -------------------------------------------------------------------------------- 1 | /**Em Java, um vetor (também conhecido como array) 2 | * é uma estrutura de dados que permite armazenar um 3 | * conjunto de elementos do mesmo tipo sob um único nome. 4 | * Cada elemento em um vetor é acessado por um índice numérico, 5 | * que começa em 0 para o primeiro elemento, 1 para o segundo elemento e assim por diante. 6 | * Vetores são úteis quando você precisa armazenar e manipular coleções ordenadas de dados.*/ 7 | package vetorArray; 8 | 9 | import java.util.Scanner; 10 | 11 | public class ParImpar { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | 15 | int[] numeros = new int[20]; 16 | int[] par; 17 | int[] impar; 18 | int pares = 0; 19 | int impares = 0; 20 | 21 | for (int i = 0; i < 20; i++) { 22 | System.out.print("Digite o número " + (i + 1) + ": "); 23 | numeros[i] = sc.nextInt(); 24 | 25 | if (numeros[i] % 2 == 0) { 26 | pares++; 27 | } else { 28 | impares++; 29 | } 30 | } 31 | 32 | par = new int[pares]; 33 | impar = new int[impares]; 34 | 35 | int numPares = 0; 36 | int numImpares = 0; 37 | 38 | for (int i = 0; i < 20; i++) { 39 | if (numeros[i] % 2 == 0) { 40 | par[numPares] = numeros[i]; 41 | numPares++; 42 | } else { 43 | impar[numImpares] = numeros[i]; 44 | numImpares++; 45 | } 46 | } 47 | 48 | System.out.println("Números pares:"); 49 | for (int i = 0; i < pares; i++) { 50 | System.out.print(par[i] + " "); 51 | } 52 | System.out.println(); 53 | 54 | System.out.println("Números ímpares:"); 55 | for (int i = 0; i < impares; i++) { 56 | System.out.print(impar[i] + " "); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/vetorArray/PedraPapelTesoura.java: -------------------------------------------------------------------------------- 1 | /*Criando game Pedra Papel e Tesoura*/ 2 | 3 | package vetorArray; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.util.Random; 9 | 10 | public class PedraPapelTesoura { 11 | 12 | public static void main(String[] args) { 13 | 14 | //Outra maneira de pegar o imput do usuario é utilizando a classe BufferedReader 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | Random rd = new Random(); 17 | 18 | String[] opc = { "Pedra", "Papel", "Tesoura" }; 19 | 20 | String escolhaUsuarioString = ""; 21 | 22 | System.out.println("Escolha sua jogada: 0 - Pedra, 1 - Papel, 2 - Tesoura"); 23 | 24 | try { 25 | escolhaUsuarioString = br.readLine(); 26 | } catch (IOException e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | int escolhaUsuario = Integer.parseInt(escolhaUsuarioString); 31 | 32 | if (escolhaUsuario < 0 || escolhaUsuario > 2) { 33 | System.out.println("Opção inválida. Encerrando o jogo."); 34 | return; 35 | } 36 | 37 | int escolhaComputador = rd.nextInt(3); 38 | 39 | System.out.println("Você escolheu: " + opc[escolhaUsuario]); 40 | System.out.println("Computador escolheu: " + opc[escolhaComputador]); 41 | 42 | if (escolhaUsuario == escolhaComputador) { 43 | System.out.println("___________________ \n"); 44 | System.out.println("Empate!"); 45 | } else if ((escolhaUsuario == 0 && escolhaComputador == 2) || (escolhaUsuario == 1 && escolhaComputador == 0) 46 | || (escolhaUsuario == 2 && escolhaComputador == 1)) { 47 | System.out.println("____________________ \n"); 48 | System.out.println("Você venceu!"); 49 | } else { 50 | System.out.println("____________________ \n"); 51 | System.out.println("Computador venceu!"); 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/streamselambdas/segundaaula/Aula023.java: -------------------------------------------------------------------------------- 1 | package segundaaula; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Optional; 8 | import java.util.stream.Collectors; 9 | import java.util.stream.Stream; 10 | 11 | public class Aula023 { 12 | 13 | public static void main(String[] args) { 14 | 15 | List numbers = Arrays.asList(1, 1, 3, 4, 5, 8, 0, 4, 5, 8, 3, 2, 5, 7, 9); 16 | 17 | Stream map = numbers.stream().distinct().limit(5).map(e -> e * 2); 18 | 19 | map.forEach(e -> System.out.println(e)); 20 | 21 | System.out.println("------------------------------------"); 22 | 23 | long count = numbers.stream().filter(e -> e % 2 == 0).count(); 24 | 25 | System.out.println(count); 26 | 27 | System.out.println("------------------------------------"); 28 | 29 | Optional max = numbers.stream().max(Comparator.naturalOrder()); 30 | 31 | System.out.println(max.get()); 32 | 33 | System.out.println("------------------------------------"); 34 | 35 | Optional min = numbers.stream().min(Comparator.naturalOrder()); 36 | 37 | System.out.println(min.get()); 38 | 39 | System.out.println("------------------------------------"); 40 | 41 | List newList = numbers.stream().filter(e -> e % 3 == 0).map(e -> e * 2).collect(Collectors.toList()); 42 | 43 | System.out.println(newList); 44 | 45 | System.out.println("------------------------------------"); 46 | 47 | Map> newList2 = numbers.stream().map(e -> e * 3) 48 | .collect(Collectors.groupingBy(e -> e % 2 == 0)); 49 | 50 | System.out.println(newList2); 51 | 52 | System.out.println("------------------------------------"); 53 | 54 | String collect = numbers.stream().map(e -> String.valueOf(e)).collect(Collectors.joining("; ")); 55 | 56 | System.out.println(collect); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/streamselambdas/oitavaaula/Melhoria01.java: -------------------------------------------------------------------------------- 1 | package oitavaaula; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.Random; 13 | import java.util.regex.Pattern; 14 | import java.util.stream.IntStream; 15 | import java.util.stream.Stream; 16 | 17 | public class Melhoria01 { 18 | 19 | @SuppressWarnings("resource") 20 | public static void main(String[] args) throws IOException { 21 | 22 | // Collection 23 | List list = Arrays.asList(1, 2, 3, 4, 5, 6); 24 | list.stream().forEach(System.out::println); 25 | 26 | // Array 27 | Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6 }; 28 | Arrays.stream(intArray).forEach(System.out::println); 29 | 30 | // Stream.Of 31 | Stream.of("Eu", "Amo", "A", "Minha", "Familia").forEach(System.out::println); 32 | 33 | // IntStream.range 34 | IntStream.range(15, 25).forEach(System.out::println); 35 | 36 | // Stream.interate 37 | Stream.iterate(5, n -> n * 2).limit(20).forEach(System.out::println); 38 | 39 | // BufferedReader - lines 40 | // streams.txt -11,12,13 41 | File file = new File("src/streams.txt"); 42 | FileReader in = new FileReader(file); 43 | try (BufferedReader bufferedReader = new BufferedReader(in)) { 44 | bufferedReader.lines().forEach(System.out::println); 45 | } 46 | 47 | //Files 48 | Path path = Paths.get(""); 49 | Files.list(path).forEach(System.out::println); 50 | 51 | //Random 52 | Random ram = new Random(); 53 | ram.ints().limit(10).forEach(System.out::println); 54 | 55 | //Pattern 56 | String input = "Eu amo a Beatriz"; 57 | Pattern compile = Pattern.compile(" "); 58 | compile.splitAsStream(input).forEach(System.out::println); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/ifelse/IfElse07.java: -------------------------------------------------------------------------------- 1 | package ifelse; 2 | 3 | import java.util.Scanner; 4 | 5 | //Escreva um programa Java para encontrar o número de dias em um mês. 6 | public class IfElse07 { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int numMes; 11 | 12 | /** 13 | * A palavra-chave var foi introduzida no Java 10 como parte das melhorias na 14 | * inferência de tipos. Ela permite que o compilador infira automaticamente o 15 | * tipo de uma variável com base no valor atribuído a ela. 16 | */ 17 | var mes31 = 31; 18 | var mes30 = 30; 19 | var fev = 28; 20 | var bisex = fev + 1; 21 | 22 | System.out.print("Digite um numero que represente um mês: "); 23 | 24 | numMes = sc.nextInt(); 25 | 26 | if (numMes == 1) { 27 | System.out.println("Janeiro tem " + mes31 + " dias."); 28 | } else if (numMes == 2) { 29 | System.out.println("Fevereiro tem " + fev + " dias, se o ano for bisexto tem " + bisex + "."); 30 | } else if (numMes == 3) { 31 | System.out.println("Março tem " + mes31 + " dias."); 32 | } else if (numMes == 4) { 33 | System.out.println("Abril tem " + mes30 + " dias."); 34 | } else if (numMes == 5) { 35 | System.out.println("Maio tem " + mes31 + " dias."); 36 | } else if (numMes == 6) { 37 | System.out.println("Junho tem " + mes30 + " dias."); 38 | } else if (numMes == 7) { 39 | System.out.println("Julho tem " + mes31 + " dias."); 40 | } else if (numMes == 8) { 41 | System.out.println("Agosto tem " + mes31 + " dias."); 42 | } else if (numMes == 9) { 43 | System.out.println("Setembro tem " + mes30 + " dias."); 44 | } else if (numMes == 10) { 45 | System.out.println("Outubro tem " + mes31 + " dias."); 46 | } else if (numMes == 11) { 47 | System.out.println("Novembro tem " + mes30 + " dias."); 48 | } else if (numMes == 12) { 49 | System.out.println("Dezembro tem " + mes31 + " dias."); 50 | } else { 51 | System.out.println("Esse numero não representa um mes do ano!"); 52 | } 53 | 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/classesesuasfuncionalidades/JoptionPene02.java: -------------------------------------------------------------------------------- 1 | //Cadastro de alunos com a class JOptionPene 2 | package classesesuasfuncionalidades; 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.swing.JOptionPane; 8 | 9 | public class JoptionPene02 { 10 | private List alunos; 11 | 12 | public JoptionPene02 () { 13 | alunos = new ArrayList<>(); 14 | } 15 | 16 | public void cadastrarAluno() { 17 | String nome = JOptionPane.showInputDialog("Digite o nome do aluno:"); 18 | if (nome != null && !nome.isEmpty()) { 19 | alunos.add(nome); 20 | JOptionPane.showMessageDialog(null, "Aluno cadastrado com sucesso!"); 21 | } else { 22 | JOptionPane.showMessageDialog(null, "Nome do aluno não pode ser vazio."); 23 | } 24 | } 25 | 26 | public void listarAlunos() { 27 | if (alunos.isEmpty()) { 28 | JOptionPane.showMessageDialog(null, "Nenhum aluno cadastrado."); 29 | } else { 30 | StringBuilder lista = new StringBuilder("Lista de Alunos:\n"); 31 | for (String aluno : alunos) { 32 | lista.append(aluno).append("\n"); 33 | } 34 | JOptionPane.showMessageDialog(null, lista.toString()); 35 | } 36 | } 37 | 38 | public static void main(String[] args) { 39 | JoptionPene02 cadastro = new JoptionPene02 (); 40 | while (true) { 41 | String opcao = JOptionPane.showInputDialog("Escolha uma opção:\n1 - Cadastrar Aluno\n2 - Listar Alunos\n3 - Sair"); 42 | if (opcao == null || opcao.equals("3")) { 43 | break; 44 | } else if (opcao.equals("1")) { 45 | cadastro.cadastrarAluno(); 46 | } else if (opcao.equals("2")) { 47 | cadastro.listarAlunos(); 48 | } else { 49 | JOptionPane.showMessageDialog(null, "Opção inválida. Tente novamente."); 50 | } 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/POO/retangulo/Main03.java: -------------------------------------------------------------------------------- 1 | /*Escreva um programa Java para criar uma classe chamada “Retângulo” 2 | * com atributos de largura e altura. Calcule a área e o perímetro do retângulo. 3 | */ 4 | //OBS: me emolguei um pouco nesse aqui! rsrsr 5 | package POO.retangulo; 6 | 7 | import java.util.Scanner; 8 | 9 | public class Main03 { 10 | 11 | public static void main(String[] args) { 12 | 13 | Scanner sc = new Scanner(System.in); 14 | 15 | float lado01; 16 | float lado02; 17 | float lado03; 18 | float lado04; 19 | float area = 0; 20 | float perimetro = 0; 21 | 22 | System.out.print("Digite o valor do primeiro lado do retângulo: "); 23 | lado01 = sc.nextFloat(); 24 | 25 | System.out.print("Digite o valor do segundo lado do retângulo: "); 26 | lado02 = sc.nextFloat(); 27 | 28 | System.out.print("Digite o valor do terceiro lado do retângulo: "); 29 | lado03 = sc.nextFloat(); 30 | 31 | System.out.print("Digite o valor do quarto lado do retângulo: "); 32 | lado04 = sc.nextFloat(); 33 | 34 | if (lado01 == lado03 && lado02 == lado04 && lado01 != lado02 && lado03 != lado04) {// Para termos um retangulo 35 | // os lados opostos tem que 36 | // se iguais e ter lados 37 | // visinhos diferentes. 38 | Retangulo retangulo = new Retangulo(lado01, lado02, lado03, lado04); 39 | 40 | System.out.print("Digite A para calcular a área ou P para calcular o perimetro: "); 41 | 42 | String calc = sc.next().toUpperCase(); 43 | 44 | if (calc.equals("A")) { 45 | area = Calcula.calcularArea(retangulo); 46 | System.out.println("A área do retangulo é " + area+"m²"); 47 | 48 | }else if (calc.equals("P")) { 49 | perimetro = Calcula.calcularPerimetro(retangulo); 50 | System.out.println("O perimetro do retangulo é " + perimetro+" m²"); 51 | 52 | }else { 53 | System.out.println("Opção inválida. Escolha 'A' para área ou 'P' para perímetro."); 54 | 55 | } 56 | }else { 57 | System.out.println("Os lados não formam um retângulo, pois todos os lados opostos devem ter medidas iguais" 58 | + " e lados visinhos medidas diferentes."); 59 | 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/classesesuasfuncionalidades/JOptionPane01.java: -------------------------------------------------------------------------------- 1 | /*Essa é a classe da biblioteca Swing JOptionPane, 2 | * com ela podemos criar pop-up 3 | * e interfaces graficas com Java. 4 | * Aqui vemos um exemplo de uma calculadora com essa classe.*/ 5 | 6 | package classesesuasfuncionalidades; 7 | 8 | import javax.swing.JOptionPane; 9 | 10 | public class JOptionPane01 { 11 | 12 | public static void main(String[] args) { 13 | double num1; 14 | double num2; 15 | String[] calculo = {"+", "-", "*", "/","%"};//vetor que guarda em memoria todas as operações possiveis desta calculadora 16 | 17 | String input1 = JOptionPane.showInputDialog("Digite o primeiro número:");//showInputDialog:Mostra uma caixa de diálogo de mensagem de pergunta, solicitando entrada do usuário 18 | num1 = Double.parseDouble(input1); 19 | 20 | 21 | String inputOperacao = (String) JOptionPane.showInputDialog(null, "Selecione a operação:", "Calculadora", 22 | JOptionPane.QUESTION_MESSAGE, null, calculo, calculo[0]);//Tipo de mensagem, usado pela interface do usuário para determinar qual ícone exibir(no caso QUESTION_MESSAGE) 23 | 24 | String input2 = JOptionPane.showInputDialog("Digite o segundo número:"); 25 | num2 = Double.parseDouble(input2); 26 | 27 | double resultado = 0; 28 | switch (inputOperacao) { 29 | case "+": 30 | resultado = num1 + num2; 31 | break; 32 | case "-": 33 | resultado = num1 - num2; 34 | break; 35 | case "*": 36 | resultado = num1 * num2; 37 | break; 38 | case "/": 39 | resultado = num1 / num2; 40 | break; 41 | case "%": 42 | resultado = num2 * (num1 / 100); 43 | break; 44 | default: 45 | JOptionPane.showMessageDialog(null, "Operação inválida!"); 46 | return; 47 | } 48 | 49 | 50 | JOptionPane.showMessageDialog(null, "Resultado: " + resultado);//showMessageDialog:Abre uma caixa de diálogo de mensagem de informações intitulada "Mensagem" 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/POO/DIO/contabancaria/ContaBancaria.java: -------------------------------------------------------------------------------- 1 | /*Você é um desenvolvedor em início de carreira e foi contratado por um banco para criar um sistema básico de abertura de contas. Sua tarefa é implementar uma classe chamada "ContaBancaria" que represente uma conta bancária com as seguintes informações: número da conta, nome do titular e saldo. 2 | 3 | Entrada 4 | O programa deve solicitar ao usuário as informações necessárias para abrir uma conta bancária. A entrada deve ser feita via console (linha de comando) e deve incluir o número da conta (um valor inteiro), o nome do titular (uma sequência de caracteres) e o saldo inicial da conta (um valor decimal). 5 | 6 | Saída 7 | Após receber as informações da conta, o programa deve criar um objeto do tipo "ContaBancaria" e exibir na tela as informações dessa conta, incluindo o número da conta, o nome do titular e o saldo atual. A saída deve ser formatada de forma clara e legível para o usuário. 8 | 9 | Exemplos 10 | A tabela abaixo apresenta exemplos com alguns dados de entrada e suas respectivas saídas esperadas. Certifique-se de testar seu programa com esses exemplos e com outros casos possíveis. 11 | 12 | Entrada Saída 13 | 010101 14 | Caio Carlos 15 | 98.0 16 | 17 | Informacoes: 18 | Conta: 101010 19 | Titular: Caio Carlos 20 | Saldo: R$ 98.0 21 | 22 | 212223 23 | Carla Paiva 24 | 500.0 25 | 26 | Informacoes: 27 | Conta: 212223 28 | Titular: Carla Paiva 29 | Saldo: R$ 500.0 30 | 123456 31 | Joao Silva 32 | 1000.0 Informacoes: 33 | Conta: 123456 34 | Titular: Joao Silva 35 | Saldo: R$ 1000.0 36 | 37 | * 38 | */ 39 | package POO.DIO.contabancaria; 40 | 41 | import java.util.Scanner; 42 | 43 | public class ContaBancaria { 44 | 45 | public static void main(String[] args) { 46 | // Lendo os dados de Entrada: 47 | Scanner scanner = new Scanner(System.in); 48 | System.out.print("Digite o numero da conta: "); 49 | int numeroConta = scanner.nextInt(); 50 | scanner.nextLine(); // Consome a quebra de linha após a entrada do número da conta 51 | System.out.print("Qual o nome do titular da conta: "); 52 | String nomeTitular = scanner.nextLine(); 53 | System.out.print("Qual o saldo da conta? "); 54 | double saldo = scanner.nextDouble(); 55 | 56 | // Criar uma instância de "ContaBancaria" com os valores de Entrada. 57 | Conta conta = new Conta(numeroConta, nomeTitular, saldo); 58 | 59 | System.out.println("Informacoes:"); 60 | // Imprimir as informações da conta usando o objeto criado acima. 61 | System.out.println("Conta: " + conta.getNumero()); 62 | System.out.println("Titular: " + conta.getTitular()); 63 | System.out.println("Saldo: R$ " + conta.getSaldo()); 64 | } 65 | } 66 | 67 | class Conta { 68 | private int numero; 69 | private String titular; 70 | private double saldo; 71 | 72 | public Conta(int numero, String titular, double saldo) { 73 | this.numero = numero; 74 | this.titular = titular; 75 | this.saldo = saldo; 76 | } 77 | 78 | public int getNumero() { 79 | return numero; 80 | } 81 | 82 | public String getTitular() { 83 | return titular; 84 | } 85 | 86 | public double getSaldo() { 87 | return saldo; 88 | } 89 | } -------------------------------------------------------------------------------- /src/ifelse/IfElse08.java: -------------------------------------------------------------------------------- 1 | /* Escreva um programa Java que leve o usuário a fornecer um único caractere do alfabeto. 2 | * Imprima vogal ou consoante, dependendo da entrada do usuário. Se a entrada do usuário não 3 | * for uma letra (entre a e z ou A e Z), ou for uma string de comprimento > 1*/ 4 | package ifelse; 5 | 6 | import java.util.Scanner; 7 | 8 | public class IfElse08 { 9 | 10 | public static void main(String[] args) { 11 | 12 | Scanner sc = new Scanner(System.in); 13 | 14 | var vog = "Vogal"; 15 | var con = "Consoante"; 16 | String letra; 17 | 18 | System.out.print("Digite uma letra do alfabeto: "); 19 | 20 | letra = sc.nextLine(); 21 | 22 | /** SER DEV TAMBÉM ENVOLVE PESQUISAR SOBRE A TAREFA A SER FEITA 23 | * 24 | * Tradicionalmente, havia apenas cinco vogais na língua portuguesa (a e i o u) 25 | * e dezoito consoantes. Essa situação sofreu alteração com a entrada das letras 26 | * k, y, w no alfabeto português: 27 | * 28 | * O y é uma vogal porque representa o som [i]; O k é uma consoante porque 29 | * representa o som [k]; O w é uma vogal quando representa o som [u] e uma 30 | * consoante quando representa o som [v] 31 | */ 32 | 33 | if (letra.equals("a") || (letra.equals("A"))) { 34 | System.out.println(vog); 35 | } else if (letra.equals("b") || (letra.equals("B"))) { 36 | System.out.println(con); 37 | } else if (letra.equals("C") || (letra.equals("C"))) { 38 | System.out.println(con); 39 | } else if (letra.equals("d") || (letra.equals("D"))) { 40 | System.out.println(con); 41 | } else if (letra.equals("e") || (letra.equals("E"))) { 42 | System.out.println(vog); 43 | } else if (letra.equals("f") || (letra.equals("F"))) { 44 | System.out.println(con); 45 | } else if (letra.equals("g") || (letra.equals("G"))) { 46 | System.out.println(con); 47 | } else if (letra.equals("h") || (letra.equals("H"))) { 48 | System.out.println(con); 49 | } else if (letra.equals("i") || (letra.equals("I"))) { 50 | System.out.println(vog); 51 | } else if (letra.equals("j") || (letra.equals("J"))) { 52 | System.out.println(con); 53 | } else if (letra.equals("k") || (letra.equals("K"))) { 54 | System.out.println(con); 55 | } else if (letra.equals("l") || (letra.equals("L"))) { 56 | System.out.println(con); 57 | } else if (letra.equals("m") || (letra.equals("M"))) { 58 | System.out.println(con); 59 | } else if (letra.equals("n") || (letra.equals("N"))) { 60 | System.out.println(con); 61 | } else if (letra.equals("o") || (letra.equals("O"))) { 62 | System.out.println(vog); 63 | } else if (letra.equals("p") || (letra.equals("P"))) { 64 | System.out.println(con); 65 | } else if (letra.equals("q") || (letra.equals("Q"))) { 66 | System.out.println(con); 67 | } else if (letra.equals("r") || (letra.equals("R"))) { 68 | System.out.println(con); 69 | } else if (letra.equals("s") || (letra.equals("S"))) { 70 | System.out.println(con); 71 | } else if (letra.equals("t") || (letra.equals("T"))) { 72 | System.out.println(con); 73 | } else if (letra.equals("u") || (letra.equals("U"))) { 74 | System.out.println(con); 75 | } else if (letra.equals("v") || (letra.equals("V"))) { 76 | System.out.println(con); 77 | } else if (letra.equals("w") || (letra.equals("W"))) { 78 | System.out.println(con + " e " + vog); 79 | } else if (letra.equals("x") || (letra.equals("X"))) { 80 | System.out.println(con); 81 | } else if (letra.equals("y") || (letra.equals("Y"))) { 82 | System.out.println(vog); 83 | } else if (letra.equals("z") || (letra.equals("Z"))) { 84 | System.out.println(con); 85 | } else if (letra.length() > 1) { 86 | System.out.println("Digite apenas uma letra!"); 87 | } else { 88 | System.out.println("Esse não é um caractere valido!"); 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/POO/DIO/contabancaria2/ContaBancaria2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Desafio 3 | Após o sucesso no desenvolvimento do sistema básico de abertura de contas bancárias, o banco decidiu expandir seus serviços para oferecer diferentes tipos de contas. Agora, além das contas bancárias comuns, eles também oferecem contas poupança. Sua tarefa é implementar a herança e o polimorfismo no sistema, criando uma classe "ContaPoupanca" que herde da classe "ContaBancaria" anteriormente criada. A classe "ContaPoupanca" deve adicionar um novo atributo, taxa de juros, além dos atributos herdados. 4 | 5 | Dica: Utilize a herança para criar a classe "ContaPoupanca" que herde da classe "ContaBancaria" e adicione o atributo "taxaJuros". Implemente o método "exibirInformacoes()" na classe "ContaPoupanca" para exibir as informações adicionais. 6 | 7 | Entrada 8 | O programa deve solicitar ao usuário as informações necessárias para abrir uma conta poupança. A entrada deve ser feita via console (linha de comando) e deve incluir o número da conta (um valor inteiro), o nome do titular (uma sequência de caracteres), o saldo inicial da conta (um valor decimal) e a taxa de juros da conta poupança (um valor decimal). 9 | 10 | Saída 11 | Após receber as informações da conta poupança, o programa deve criar um objeto do tipo "ContaPoupanca" e exibir na tela as informações dessa conta, incluindo o número da conta, o nome do titular, o saldo atual e a taxa de juros. A saída deve ser formatada de forma clara e legível para o usuário. 12 | 13 | Exemplos 14 | A tabela abaixo apresenta exemplos com alguns dados de entrada e suas respectivas saídas esperadas. Certifique-se de testar seu programa com esses exemplos e com outros casos possíveis. 15 | 16 | Entrada Saída 17 | Joao 18 | 123456 19 | 1000.0 20 | 1.5 Conta Poupanca: 21 | Joao 22 | 123456 23 | Saldo: R$ 1000.0 24 | Taxa de juros: 1.5% 25 | Ana 26 | 789012 27 | 2500.0 28 | 3.0 Conta Poupanca: 29 | Ana 30 | 789012 31 | Saldo: R$ 2500.0 32 | Taxa de juros: 3.0% 33 | Maria 34 | 987654 35 | 500.0 36 | 2.5 Conta Poupanca: 37 | Maria 38 | 987654 39 | Saldo: R$ 500.0 40 | Taxa de juros: 2.5% 41 | */ 42 | package POO.DIO.contabancaria2; 43 | import java.text.DecimalFormat; 44 | import java.util.Scanner; 45 | 46 | public class ContaBancaria2 { 47 | 48 | public static void main(String[] args) { 49 | // Lendo os dados de Entrada: 50 | Scanner scanner = new Scanner(System.in); 51 | System.out.println("Qual o nome do titular?"); 52 | String titular = scanner.nextLine(); 53 | System.out.println("Qual o numero da conta?"); 54 | int numeroConta = scanner.nextInt(); 55 | System.out.println("Qual o saldo da conta?"); 56 | double saldo = scanner.nextDouble(); 57 | System.out.println("Qual a taxa de juros?"); 58 | double taxaJuros = scanner.nextDouble(); 59 | 60 | ContaPoupanca contaPoupanca = new ContaPoupanca(numeroConta, titular, saldo, taxaJuros); 61 | 62 | System.out.println("Conta Poupanca:"); 63 | contaPoupanca.exibirInformacoes(); 64 | } 65 | } 66 | 67 | class ContaBancaria { 68 | protected int numero; 69 | protected String titular; 70 | protected double saldo; 71 | 72 | public ContaBancaria(int numero, String titular, double saldo) { 73 | this.numero = numero; 74 | this.titular = titular; 75 | this.saldo = saldo; 76 | } 77 | 78 | public void exibirInformacoes() { 79 | DecimalFormat decimalFormat = new DecimalFormat("#.0"); 80 | System.out.println(titular); 81 | System.out.println(numero); 82 | System.out.println("Saldo: R$ " + decimalFormat.format(saldo)); 83 | } 84 | } 85 | 86 | class ContaPoupanca extends ContaBancaria { 87 | private double taxaJuros; 88 | 89 | public ContaPoupanca(int numero, String titular, double saldo, double taxaJuros) { 90 | super(numero, titular, saldo); 91 | this.taxaJuros = taxaJuros; 92 | } 93 | 94 | public void exibirInformacoes() { 95 | super.exibirInformacoes(); 96 | DecimalFormat decimalFormat = new DecimalFormat("#.0"); 97 | System.out.println("Taxa de juros: " + decimalFormat.format(taxaJuros) + "%"); 98 | } 99 | } -------------------------------------------------------------------------------- /src/streamselambdas/quintaaula/Collect01.java: -------------------------------------------------------------------------------- 1 | package quintaaula; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Comparator; 6 | import java.util.IntSummaryStatistics; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Set; 10 | import java.util.TreeSet; 11 | import java.util.stream.Collectors; 12 | 13 | public class Collect01 { 14 | 15 | public static void main(String[] args) { 16 | 17 | List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); 18 | 19 | // supplier-fornecedor 20 | // accumulator-acumulador 21 | // combiner-combinação 22 | List collecList = list.stream().collect(() -> new ArrayList<>(), 23 | (l, e) -> l.add(e), 24 | (l1, l2) -> l1.addAll(l2)); 25 | 26 | System.out.println(collecList); 27 | System.out.println(list); 28 | System.out.println("----------------------------------------------------------"); 29 | 30 | //toList 31 | 32 | List collecList2 = list.stream() 33 | .filter((n) -> n % 2 == 0) 34 | .collect(Collectors.toList()); 35 | System.out.println(collecList2); 36 | System.out.println("----------------------------------------------------------"); 37 | 38 | //toSet 39 | 40 | Set collecList3 = list.stream() 41 | .filter((n) -> n % 2 == 0) 42 | .collect(Collectors.toCollection(() -> new TreeSet<>()));//metodo toCollection() eu posso escolher a 43 | System.out.println(collecList3); //implementação da Collection que eu quiser 44 | System.out.println("----------------------------------------------------------"); 45 | 46 | //join - serve para unir String 47 | 48 | String join01 = list.stream() 49 | .map(n -> n.toString())//transforma todos os elementos em String antes de concatenar. 50 | .collect(Collectors.joining("; ")); 51 | System.out.println(join01); 52 | System.out.println("----------------------------------------------------------"); 53 | 54 | //averaging - tira a media de todos os elementos 55 | 56 | Double media = list.stream().collect(Collectors.averagingInt( n -> n.intValue())); 57 | System.out.println(media); 58 | System.out.println("----------------------------------------------------------"); 59 | 60 | //summing - soma todos os elementos da lista 61 | 62 | Integer soma = list.stream().collect(Collectors.summingInt( n -> n.intValue())); 63 | System.out.println(soma); 64 | System.out.println("----------------------------------------------------------"); 65 | 66 | //counting - diz quantos elementos tem em uma lista 67 | 68 | Long collect4 = list.stream().collect(Collectors.counting()); 69 | System.out.println(collect4); 70 | System.out.println("----------------------------------------------------------"); 71 | 72 | //min - pega o menor elemento de uma lista /max - pega o maior elemento de uma lista 73 | 74 | list.stream().collect(Collectors.minBy(Comparator.naturalOrder())).ifPresent(System.out::println); 75 | list.stream().collect(Collectors.maxBy(Comparator.naturalOrder())).ifPresent(System.out::println); 76 | System.out.println("----------------------------------------------------------"); 77 | 78 | //summarizing - nos da um monte de possibilidades 79 | 80 | IntSummaryStatistics soma2 = list.stream().collect(Collectors.summarizingInt( n -> n.intValue())); 81 | System.out.println(soma2.getAverage()); 82 | System.out.println(soma2.getCount()); 83 | System.out.println(soma2.getMax()); 84 | System.out.println(soma2.getMin()); 85 | System.out.println(soma2.getSum()); 86 | System.out.println("----------------------------------------------------------"); 87 | 88 | //groupinBy - retorna um Map de acordo com a logica escolhida pelo programador 89 | 90 | Map> groupinByEx01 = list.stream().collect(Collectors.groupingBy((n) -> n % 3)); 91 | System.out.println(groupinByEx01); 92 | System.out.println("----------------------------------------------------------"); 93 | 94 | //partitioningBy - agrupa sempre em true e false e retorna dois grupos 95 | 96 | Map> groupinByEx02 = list.stream().collect(Collectors.partitioningBy((n) -> n % 3 == 0)); 97 | System.out.println(groupinByEx02); 98 | System.out.println("----------------------------------------------------------"); 99 | 100 | //toMap 101 | 102 | Map groupinByEx03 = list.stream().collect(Collectors.toMap((n) -> n, n -> n * 5)); 103 | System.out.println(groupinByEx03); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/eclipse,intellij,androidstudio 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,intellij,androidstudio 3 | 4 | ### Eclipse ### 5 | .metadata 6 | bin/ 7 | tmp/ 8 | *.tmp 9 | *.bak 10 | *.swp 11 | *~.nib 12 | local.properties 13 | .settings/ 14 | .loadpath 15 | .recommenders 16 | 17 | # External tool builders 18 | .externalToolBuilders/ 19 | 20 | # Locally stored "Eclipse launch configurations" 21 | *.launch 22 | 23 | # PyDev specific (Python IDE for Eclipse) 24 | *.pydevproject 25 | 26 | # CDT-specific (C/C++ Development Tooling) 27 | .cproject 28 | 29 | # CDT- autotools 30 | .autotools 31 | 32 | # Java annotation processor (APT) 33 | .factorypath 34 | 35 | # PDT-specific (PHP Development Tools) 36 | .buildpath 37 | 38 | # sbteclipse plugin 39 | .target 40 | 41 | # Tern plugin 42 | .tern-project 43 | 44 | # TeXlipse plugin 45 | .texlipse 46 | 47 | # STS (Spring Tool Suite) 48 | .springBeans 49 | 50 | # Code Recommenders 51 | .recommenders/ 52 | 53 | # Annotation Processing 54 | .apt_generated/ 55 | .apt_generated_test/ 56 | 57 | # Scala IDE specific (Scala & Java development for Eclipse) 58 | .cache-main 59 | .scala_dependencies 60 | .worksheet 61 | 62 | # Uncomment this line if you wish to ignore the project description file. 63 | # Typically, this file would be tracked if it contains build/dependency configurations: 64 | #.project 65 | 66 | ### Eclipse Patch ### 67 | # Spring Boot Tooling 68 | .sts4-cache/ 69 | 70 | ### Intellij ### 71 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 72 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 73 | 74 | # User-specific stuff 75 | .idea/**/workspace.xml 76 | .idea/**/tasks.xml 77 | .idea/**/usage.statistics.xml 78 | .idea/**/dictionaries 79 | .idea/**/shelf 80 | 81 | # AWS User-specific 82 | .idea/**/aws.xml 83 | 84 | # Generated files 85 | .idea/**/contentModel.xml 86 | 87 | # Sensitive or high-churn files 88 | .idea/**/dataSources/ 89 | .idea/**/dataSources.ids 90 | .idea/**/dataSources.local.xml 91 | .idea/**/sqlDataSources.xml 92 | .idea/**/dynamic.xml 93 | .idea/**/uiDesigner.xml 94 | .idea/**/dbnavigator.xml 95 | 96 | # Gradle 97 | .idea/**/gradle.xml 98 | .idea/**/libraries 99 | 100 | # Gradle and Maven with auto-import 101 | # When using Gradle or Maven with auto-import, you should exclude module files, 102 | # since they will be recreated, and may cause churn. Uncomment if using 103 | # auto-import. 104 | # .idea/artifacts 105 | # .idea/compiler.xml 106 | # .idea/jarRepositories.xml 107 | # .idea/modules.xml 108 | # .idea/*.iml 109 | # .idea/modules 110 | # *.iml 111 | # *.ipr 112 | 113 | # CMake 114 | cmake-build-*/ 115 | 116 | # Mongo Explorer plugin 117 | .idea/**/mongoSettings.xml 118 | 119 | # File-based project format 120 | *.iws 121 | 122 | # IntelliJ 123 | out/ 124 | 125 | # mpeltonen/sbt-idea plugin 126 | .idea_modules/ 127 | 128 | # JIRA plugin 129 | atlassian-ide-plugin.xml 130 | 131 | # Cursive Clojure plugin 132 | .idea/replstate.xml 133 | 134 | # SonarLint plugin 135 | .idea/sonarlint/ 136 | 137 | # Crashlytics plugin (for Android Studio and IntelliJ) 138 | com_crashlytics_export_strings.xml 139 | crashlytics.properties 140 | crashlytics-build.properties 141 | fabric.properties 142 | 143 | # Editor-based Rest Client 144 | .idea/httpRequests 145 | 146 | # Android studio 3.1+ serialized cache file 147 | .idea/caches/build_file_checksums.ser 148 | 149 | ### Intellij Patch ### 150 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 151 | 152 | # *.iml 153 | # modules.xml 154 | # .idea/misc.xml 155 | # *.ipr 156 | 157 | # Sonarlint plugin 158 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 159 | .idea/**/sonarlint/ 160 | 161 | # SonarQube Plugin 162 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 163 | .idea/**/sonarIssues.xml 164 | 165 | # Markdown Navigator plugin 166 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 167 | .idea/**/markdown-navigator.xml 168 | .idea/**/markdown-navigator-enh.xml 169 | .idea/**/markdown-navigator/ 170 | 171 | # Cache file creation bug 172 | # See https://youtrack.jetbrains.com/issue/JBR-2257 173 | .idea/$CACHE_FILE$ 174 | 175 | # CodeStream plugin 176 | # https://plugins.jetbrains.com/plugin/12206-codestream 177 | .idea/codestream.xml 178 | 179 | # Azure Toolkit for IntelliJ plugin 180 | # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij 181 | .idea/**/azureSettings.xml 182 | 183 | ### AndroidStudio ### 184 | # Covers files to be ignored for android development using Android Studio. 185 | 186 | # Built application files 187 | *.apk 188 | *.ap_ 189 | *.aab 190 | 191 | # Files for the ART/Dalvik VM 192 | *.dex 193 | 194 | # Java class files 195 | *.class 196 | 197 | # Generated files 198 | gen/ 199 | 200 | # Gradle files 201 | .gradle 202 | .gradle/ 203 | build/ 204 | 205 | # Signing files 206 | .signing/ 207 | 208 | # Local configuration file (sdk path, etc) 209 | 210 | # Proguard folder generated by Eclipse 211 | proguard/ 212 | 213 | # Log Files 214 | *.log 215 | 216 | # Android Studio 217 | /*/build/ 218 | /*/local.properties 219 | /*/out 220 | /*/*/build 221 | /*/*/production 222 | captures/ 223 | .navigation/ 224 | *.ipr 225 | *~ 226 | 227 | # Keystore files 228 | *.jks 229 | *.keystore 230 | 231 | # Google Services (e.g. APIs or Firebase) 232 | # google-services.json 233 | 234 | # Android Patch 235 | gen-external-apklibs 236 | 237 | # External native build folder generated in Android Studio 2.2 and later 238 | .externalNativeBuild 239 | 240 | # NDK 241 | obj/ 242 | 243 | # IntelliJ IDEA 244 | *.iml 245 | /out/ 246 | 247 | # User-specific configurations 248 | .idea/caches/ 249 | .idea/libraries/ 250 | .idea/shelf/ 251 | .idea/workspace.xml 252 | .idea/tasks.xml 253 | .idea/.name 254 | .idea/compiler.xml 255 | .idea/copyright/profiles_settings.xml 256 | .idea/encodings.xml 257 | .idea/misc.xml 258 | .idea/modules.xml 259 | .idea/scopes/scope_settings.xml 260 | .idea/dictionaries 261 | .idea/vcs.xml 262 | .idea/jsLibraryMappings.xml 263 | .idea/datasources.xml 264 | .idea/dataSources.ids 265 | .idea/sqlDataSources.xml 266 | .idea/dynamic.xml 267 | .idea/uiDesigner.xml 268 | .idea/assetWizardSettings.xml 269 | .idea/gradle.xml 270 | .idea/jarRepositories.xml 271 | .idea/navEditor.xml 272 | 273 | # Legacy Eclipse project files 274 | .classpath 275 | .project 276 | 277 | # Mobile Tools for Java (J2ME) 278 | .mtj.tmp/ 279 | 280 | # Package Files # 281 | *.war 282 | *.ear 283 | 284 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 285 | hs_err_pid* 286 | 287 | ## Plugin-specific files: 288 | 289 | # mpeltonen/sbt-idea plugin 290 | 291 | # JIRA plugin 292 | 293 | # Mongo Explorer plugin 294 | .idea/mongoSettings.xml 295 | 296 | # Crashlytics plugin (for Android Studio and IntelliJ) 297 | 298 | ### AndroidStudio Patch ### 299 | 300 | !/gradle/wrapper/gradle-wrapper.jar 301 | 302 | # End of https://www.toptal.com/developers/gitignore/api/eclipse,intellij,androidstudio --------------------------------------------------------------------------------