samedi 20 novembre 2021

i need to check if a number is equal,2x,3x,4x,5x bigger than the other how do i do this?

so basically I just need this program to tell me is if a>b and by how much so the things I need to know are if a==b, a>b,b<a and I also need to know how many times grater which ranges from 2x,3x,4x,5x,6x if the number is is greater than 6 times just print "a lot bigger " if there is a more efficient way to do this then please give me suggestions but the problem with this code is that it does not go past the first condition of (a>b||a/b<1||a/b>0)

import java.util.Scanner;

public class Main {

public static void main(String[] args) {



    Scanner input =new Scanner(System.in);

    System.out.println("what is the value for a");
    double a =input.nextDouble();
    System.out.println("what is the value for b");
    double b =input.nextDouble();


    if (a==b){
        System.out.println("a is equal to b");
    }
    else if (a>b||a/b<1||a/b>0){
        System.out.println("a is slightly bigger than b");

    }
    else if (a>b||a/b<3||a/b>=2) {
        System.out.println("a is 2x bigger than b");
    }
    else if (a>b||a/b<4||a/b>=3) {
        System.out.println("a is 3x bigger than b");
    }
    else if (a>b||a/b<5||a/b>=4) {
        System.out.println("a is 4x bigger than b");
    }

    else if (a>b||a/b<6||a/b>=5) {
        System.out.println("a is 5x bigger than b");
    }

    else if (a>b||a/b<100||a/b>6){
        System.out.println("a is alot bigger than b");
    }
    // to check if b is bigger than a
    else if (a<b||b/a<1||b/a>0){
        System.out.println("b is slightly bigger than a");

    }
    else if (a<b||b/a<3||b/a>=2) {
        System.out.println("b is 2x bigger than a");
    }
    else if (a<b||b/a<4||b/a>=3) {
        System.out.println("b is 3x bigger than a");
    }
    else if (a<b||b/a<5||b/a>=4) {
        System.out.println("b is 4x bigger than a");
    }

    else if (a<b||b/a<6||b/a>=5) {
        System.out.println("b is 5x bigger than a");
    }

// to check if its alot bigger

    else if (a>b||a/b<100||a/b>6){
        System.out.println("a is alot bigger than b");



    }



}}

Aucun commentaire:

Enregistrer un commentaire