Return False or True

Asked

Viewed 569 times

0

I need to know if the second number is multiple of the first number, if yes return true otherwise false, I’m having trouble declaring the library Boolean.

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;
            }
        }
    }  
  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

2 answers

1

The whole code doesn’t seem to make sense. It’s creating two readers, it’s not reading anything, it’s out of order, then it declares variables that it doesn’t use, here comes a lot of things that are completely meaningless, and it talks in a Boolean library that is a type of data. I suggest finding a structured way to learn.

To know if one number is multiple of another one has to know if the rest of the division between them is 0. And just, It’s that simple:

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");
    }
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

0

Your code does not have much logic, to do this exercise just think about the rest of the division, if the rest of the division of the first by 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);
    }

 }

}

Browser other questions tagged

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