Advertisement
VIISeptem

Untitled

Feb 7th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. public class Binär{
  2.     public String toBinary(int n){
  3.         // 1. Erzeuge einen leeren String
  4.        
  5.         String output= "";
  6.         // 2.
  7.         int wert = 16;
  8.         do{
  9.            
  10.             if (n % 2 == 0){
  11.                 output =  "0" + output;
  12.              
  13.             }else{
  14.                 output = "1" +  output;
  15.             }
  16.             n = n / 2;
  17.         }while(n > 0);
  18.  
  19.         // 3. Gib den fertigen String zurück
  20.         return output;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement