Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zmluki;
- import java.util.*;
- public class ZMLuki {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.println("Podaj liczbę: ");
- int liczba = sc.nextInt();
- int bit_znakowy = 0;
- if(liczba < 0){
- bit_znakowy = 1;
- liczba *= -1;
- }
- String zm = "";
- while(liczba > 0){
- zm += liczba % 2;
- liczba /= 2;
- }
- char[] tab = new char[zm.length()];
- for(int i=0; i< tab.length; i++){
- int x = zm.length() - (1 + i);
- tab[i] = zm.charAt(x);
- }
- System.out.print(bit_znakowy + ".");
- for(int i=0;i<tab.length;i++)
- System.out.print(tab[i]);
- }
- }
Add Comment
Please, Sign In to add comment