Git Product home page Git Product logo

erro-solucao-java-analise-de-numeros's Introduction

Exercicio (Java): Análise de Números

O exercicio publicado é referente ao treinamento do Bootcamp Java - Aritméticos em Java (https://digitalinnovation.one)

Descrição do Desafio:

Você deve fazer a leitura de 5 valores inteiros. Em seguida mostre quantos valores informados são pares, quantos valores informados são ímpares, quantos valores informados são positivos e quantos valores informados são negativos.

Entrada:

Você receberá 5 valores inteiros.

Saída:

Exiba a mensagem conforme o exemplo de saída abaixo, sendo uma mensagem por linha e não esquecendo o final de linha após cada uma.

Exemplos de Entrada Exemplos de Saída
-5 3 valor(es) par(es)
0 2 valor(es) impar(es)
-3 1 valor(es) positivo(s)
-4 3 valor(es) negativo(s)
12

Java 

//SOLUCAO 1

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class AnaliseDeNumeros {
    public static void main(String[] args) throws IOException {

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st;
      
      int numeroEntrada, contNumPar = 0, contNumImpar = 0, contNumPostitivo = 0, contNumNegativo = 0;
      
      for (int  i = 0; i < 5; i++) {
        
        st = new StringTokenizer(br.readLine());
        numeroEntrada = Integer.parseInt(st.nextToken());
        
        if (numeroEntrada % 2 == 0) contNumPar++;  // valida numeros pares
        if (Math.abs(numeroEntrada % 2) == 1) contNumImpar++; // valida numeros impares
        if (numeroEntrada > 0) contNumPostitivo++; // valida numeros positivos
        if (numeroEntrada < 0) contNumNegativo++; // valida numeros negativos
        
      }
  
      System.out.println(
        contNumPar + " valor(es) par(es)" + "\n" +
        contNumImpar + " valor(es) impar(es)" + "\n" +
        contNumPostitivo + " valor(es) positivo(s)" + "\n" +
        contNumNegativo + " valor(es) negativo(s)"
      );
      
      br.close();
  }
}

erro-solucao-java-analise-de-numeros's People

Contributors

camila-github avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.