SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         String input = "";
  8.         double result = Double.POSITIVE_INFINITY;
  9.         double first = 0;
  10.         double second = 0;
  11.         double third = 0;
  12.         double division = 0;
  13.         boolean valid = false;
  14.         System.out.println("This program calculates the least ratio of numbers");
  15.         Scanner scan = new Scanner(System.in);
  16.         do {
  17.             System.out.println("Enter number 1: ");
  18.             try {
  19.                 first = scan.nextInt();
  20.                 if (first != Double.POSITIVE_INFINITY) {
  21.                     valid = true;
  22.                 } else {
  23.                     valid = false;
  24.                 }
  25.             } catch (Exception e) {
  26.                 scan.nextLine();
  27.                 System.out.println("Error Message!");
  28.             }
  29.         }
  30.         while (valid=false);
  31.  
  32.         valid = false ;
  33.         do {
  34.             System.out.println("Enter number 2: ");
  35.             try {
  36.                 second = scan.nextInt();
  37.                 if (second != Double.POSITIVE_INFINITY) {
  38.                     valid = true;
  39.                 } else {
  40.                     valid = false;
  41.                 }
  42.             } catch (Exception e) {
  43.                 scan.nextLine();
  44.                 System.out.println("Error Message!");
  45.             }
  46.         }
  47.         while (valid=false);
  48.         valid = false;
  49.         do {
  50.             System.out.println("Enter number 3: ");
  51.             try {
  52.                 third = scan.nextInt();
  53.                 if (third != Double.POSITIVE_INFINITY) {
  54.                     valid = true;
  55.                 } else {
  56.                     valid = false;
  57.                 }
  58.             } catch (Exception e) {
  59.                 scan.nextLine();
  60.                 System.out.println("Error Message!");
  61.             }
  62.         }
  63.         while (valid=false);
  64.         if (first!=0) {
  65.             division = (second / first < third / first) ? second / first : third / first;
  66.             if(division < result) {
  67.                 result = division;
  68.             }
  69.             if (second !=0) {
  70.                 division = (first / second < third / second) ? first / second : third / second;
  71.                 if(division < result) {
  72.                     result = division;
  73.         }
  74.                 if (third !=0) {
  75.                     division = (first / third < second / third) ? first / third : second / third;
  76.                     if(division < result) {
  77.                         result = division;
  78.                         if result = Double.POSITIVE_INFINITY {
  79.                             System.out.print("Result: Infinity");
  80.  
  81.                         } else {
  82.                             System.out.print("'Result: ', Result:Length(IntToStr(Floor(Result))) + 6:5)");
  83.  
  84.                         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top