Guest User

Untitled

a guest
Oct 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package quintaQuestao;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DesigualdadeTriangular {
  6.  
  7.     /**
  8.      * @param args
  9.      */
  10.     public static void main(String[] args) {
  11.         Scanner in = new Scanner(System.in);
  12.         String grupo;
  13.         String l1, l2, l3;
  14.         int possivel, impossivel, ld1, ld2, ld3, sim, nao;
  15.  
  16.         possivel = 0;
  17.         impossivel = 0;
  18.         sim = 0;
  19.         nao = 0;
  20.  
  21.         System.out.println("Digite o valor dos lados do triangulo, separando-os por espaço");
  22.         do {
  23.             grupo = in.nextLine();
  24.             l1 = grupo.substring(0, grupo.indexOf(32));
  25.             l2 = grupo.substring(grupo.indexOf(32) + 1, grupo.lastIndexOf(32));
  26.             l3 = grupo.substring(grupo.lastIndexOf(32) + 1, grupo.length());
  27.             ld1 = Integer.parseInt(l1);
  28.             ld2 = Integer.parseInt(l2);
  29.             ld3 = Integer.parseInt(l3);
  30.  
  31.             if ((ld1 > ld2) && (ld2 > ld3)) {
  32.                 if ((ld1 < ld2 + ld3) && (ld3 > ld1 - ld2)) {
  33.                     possivel++;
  34.                 } else {
  35.                     impossivel--;
  36.                 }
  37.  
  38.             } else if ((ld1 > ld2) && (ld3 > ld2)) {
  39.                 if ((ld1 < ld2 + ld3) && (ld2 > ld1 - ld2)) {
  40.                     possivel++;
  41.                 } else {
  42.                     impossivel--;
  43.                 }
  44.  
  45.             } else if ((ld2 > ld1) && (ld1 > ld3)) {
  46.                 if ((ld2 < ld1 + ld3) && (ld3 > ld2 - ld1)) {
  47.                     possivel++;
  48.                 } else {
  49.                     impossivel--;
  50.                 }
  51.  
  52.             } else if ((ld2 > ld1) && (ld3 > ld1)) {
  53.                 if ((ld2 < ld2 + ld3) && (ld1 > ld2 - ld3)) {
  54.                     possivel++;
  55.                 } else {
  56.                     impossivel--;
  57.                 }
  58.  
  59.             } else if ((ld3 > ld1) && (ld1 > ld2)) {
  60.                 if ((ld3 < ld2 + ld3) && (ld2 > ld3 - ld2)) {
  61.                     possivel++;
  62.                 } else {
  63.                     impossivel--;
  64.                 }
  65.  
  66.             } else if ((ld3 > ld1) && (ld2 > ld1)) {
  67.                 if ((ld3 < ld2 + ld1) && (ld1 > ld3 - ld2)) {
  68.                     possivel++;
  69.                 } else {
  70.                     impossivel--;
  71.                 }
  72.  
  73.             }
  74.                 sim = +possivel;
  75.                 nao = +impossivel;
  76.    
  77.         } while (!grupo.equals("0 0 0"));
  78.        
  79.            
  80.            
  81.        
  82.        
  83.        
  84.        
  85.         {
  86.         System.out.println("Possíveis: " + sim);
  87.         System.out.println("Impossíveis: " + nao);
  88.         }
  89.  
  90.     }
  91.  
  92. }
Add Comment
Please, Sign In to add comment