Advertisement
Kushtrim

Rrumbullaksimi

Oct 22nd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.  
  2. /**
  3.  * @author Kushtrim
  4.  * @version 1.01
  5.  */
  6. public class Gabimet
  7. {
  8.     public static void main (String[] args)
  9.     {    
  10.        
  11.         System.out.println(rrumbullakso(1.38564,3));
  12.     }
  13.    
  14.     public static double rrumbullakso ( double nr , int saShifra )
  15.     {
  16.         int[] vargu = new int[(nr+"").length()-1];
  17.        
  18.         int pozitaEPresjes  = (nr+"").indexOf(".");
  19.        
  20.         if ( pozitaEPresjes ==1 && Integer.parseInt((nr+"").charAt(0)+"") == 0 )
  21.         {
  22.             saShifra++;
  23.         }
  24.         System.out.println(nr);
  25.         int k=0;
  26.         for ( int i = 0 ; i<vargu.length;i++)
  27.         {
  28.             if ( i == pozitaEPresjes) { k++;}
  29.             vargu[i] =Integer.parseInt( (nr+"").charAt(i+k)+"");
  30.            ;
  31.         }
  32.        
  33.         for ( int i = vargu.length-1 ; i>=saShifra ; i--)
  34.         {
  35.             if ( vargu[i] >=5 )
  36.             {
  37.                vargu[i-1]++;
  38.             }
  39.         }
  40.        
  41.        for ( int i = 0 ; i<vargu.length;i++)
  42.         {
  43.             System.out.println(vargu[i]);
  44.         }
  45.        
  46.         String answerStr = "";
  47.         for( int i = 0; i <saShifra; i++)
  48.         {
  49.             if ( i == pozitaEPresjes)
  50.             {
  51.                 answerStr += ".";
  52.             }
  53.             answerStr += vargu[i];
  54.         }
  55.        
  56.         double answer =  Double.parseDouble(answerStr);
  57.        
  58.         if (saShifra<pozitaEPresjes)
  59.         {
  60.             answer = answer*Math.pow(10,pozitaEPresjes-saShifra);
  61.         }
  62.        
  63.         return answer;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement