Why do I try to divide the value of 0?

Asked

Viewed 33 times

0

package com.company;

import java.util.Scanner;

public class Lista3 {
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);


        System.out.println("Qual o valor do seu salario ?");
        int salariodousuario = entrada.nextInt();

        int salariominimo = 1100;

        int quantidadeDesalariosminimos = salariominimo/salariodousuario;

        System.out.println("Você ganha um total de " + quantidadeDesalariosminimos + " salarios minimos.");


    }
}
  • aaaaaaa, thank you very much, it’s really cleared my mind now.

2 answers

2

This can happen if you receive a floar or double as a result. guy:

1 / 2 = 0.5

as you store the result in a variable of the whole type so it(the variable) will simply take the whole part.

podes tentar 3 / 2 = 1.5 e terás 1 como resultado

0

To have the average of minimum wages on top of the user’s salary Voce has to divide the user’s salary by the minimum wage. And also Voce is using int, it rounds the value down. Ex: 10/6 = 1. For an exact result uses double instead of int.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.