Return False or True

0

I need to know if the second number is a multiple of the first number, if yes return TRUE otherwise FALSE, I am not able to declare the Boolean library.

package br.fatec.com;

import java.util.Scanner;

public class Mult {


    public static void main(String args[]){

        Scanner numero1 = new Scanner(System.in);
        System.out.println("digite o primeiro numero");

        Scanner numero2 = new Scanner(System.in);
        System.out.println("digite o segundo numero");


        int num1 = 0;
        int num2 = 0;
        int mult;

        mult = (num2 % num1);

     boolean verifiva int mult; {
            if (mult >=0){
                   return True;
            }else
                   return False;
            }
        }
    }  
    
asked by anonymous 26.08.2018 / 14:08

2 answers

1

The whole code does not seem to make sense. It is creating two readers, it is not reading anything, it is out of order, then it declares variables that it does not use, there comes several things completely meaningless, and it speaks in Boolean library that is a type of data. I suggest looking for a structured way to learn.

To know if one number is a multiple of another one has to know if the remainder of the division between them is 0. And just, It's simple like this:

import java.util.Scanner;

class Mult {
    public static void main(String args[]) {
        Scanner leitor = new Scanner(System.in);
        System.out.println("digite o primeiro numero");
        int numero1 = leitor.nextInt();
        System.out.println("digite o segundo numero");
        int numero2 = leitor.nextInt();
        System.out.println(numero2 % numero1 == 0 ? "É múltiplo" : "Não é múltiplo");
    }
}
    
26.08.2018 / 14:36
0

Your code does not have much logic, to do this exercise you just think about the rest of the division, if the rest of the division from the first to the second is zero then it is multiple.

public class NumeroMultiplo {

public static void main(String[] args) {
    int numero1 =Integer.parseInt(JOptionPane.showInputDialog("Digite o numero 1 "));
    int numero2 =Integer.parseInt(JOptionPane.showInputDialog("Digite o numero 2 "));
    boolean comparacao;

    if(numero1 % numero2 == 0) {
        comparacao = true;
        JOptionPane.showMessageDialog(null, "Numero é multiplo - "+comparacao);
    } else {
        comparacao = false;
        JOptionPane.showMessageDialog(null, "Não é multiplo - " +comparacao);
    }

 }

}
    
26.08.2018 / 18:30