Guest User

Untitled

a guest
Apr 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package zmluki;
  2. import java.util.*;
  3.  
  4. public class ZMLuki {
  5.     public static void main(String[] args){
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.println("Podaj liczbę: ");
  8.         int liczba = sc.nextInt();
  9.         int bit_znakowy = 0;
  10.        
  11.         if(liczba < 0){
  12.             bit_znakowy = 1;
  13.             liczba *= -1;
  14.         }
  15.        
  16.         String zm = "";
  17.        
  18.         while(liczba > 0){
  19.             zm += liczba % 2;
  20.             liczba /= 2;
  21.         }
  22.        
  23.         char[] tab = new char[zm.length()];
  24.         for(int i=0; i< tab.length; i++){
  25.             int x = zm.length() - (1 + i);
  26.             tab[i] = zm.charAt(x);
  27.         }
  28.        
  29.         System.out.print(bit_znakowy + ".");
  30.         for(int i=0;i<tab.length;i++)
  31.             System.out.print(tab[i]);
  32.     }
  33. }
Add Comment
Please, Sign In to add comment