Advertisement
Guest User

solución con cadenas (cifras pseudosignificativas)

a guest
Aug 28th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class strings {
  4.  
  5.   public static int contarCifrasSignificativas(String n) {
  6.     int cs = 0; //cantidad de cifras significativas
  7.     int i=0;
  8.     int posicionPunto = -1;
  9.     for(; i<n.length(); i++) {      
  10.  
  11.       if(n.charAt(i) == '.')
  12.     posicionPunto = i;
  13.       else if(n.charAt(i) != '0')
  14.     break;
  15.  
  16.     }
  17.  
  18.     for(; i<n.length(); i++) {
  19.       cs++;
  20.     }
  21.  
  22.     if(Double.parseDouble(n) == 0.0)
  23.       if(posicionPunto < 0)
  24.     return 0;
  25.       else
  26.     return n.length() - posicionPunto -1;
  27.    
  28.     return cs;
  29.   }
  30.  
  31.   public static void main(String[] args) {
  32.     Scanner cin = new Scanner(System.in); // Console IN
  33.     String a = cin.nextLine(), b = cin.nextLine();
  34.     int cs = 0; //cantidad de cifras significativas
  35.    
  36.     int csa = contarCifrasSignificativas(a);
  37.     int csb = contarCifrasSignificativas(b);
  38.  
  39.     if(csa == 3 && csb == 3)
  40.       System.out.println(Double.parseDouble(a)*Double.parseDouble(b));
  41.     else
  42.       System.out.println("Las condiciones no se cumplen");
  43.   }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement