Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. public class LongBit {
  2.  
  3.     public static void main(String[] args) {
  4.         long Bit = 42;
  5.  
  6.         String Bin = Long.toBinaryString(Bit);
  7.        
  8.         boolean Last3Eq1 = Bin.endsWith( "111" );
  9.         boolean Last3Eq0 = Bin.endsWith( "000" );
  10.         boolean First3Eq1 = Bin.startsWith( "111" );
  11.         boolean Last3Eq011 = Bin.endsWith( "011" );
  12.         boolean Last3Eq001 = Bin.endsWith( "001" );
  13.         boolean Last3Eq010 = Bin.endsWith( "010" );
  14.         boolean Last3Eq101 = Bin.endsWith( "101" );
  15.        
  16.         if (Last3Eq1) {
  17.             System.out.println("Die letzten 3 Stellen enden auf 111");
  18.             }
  19.         else if (Last3Eq0) {
  20.             System.out.println("Die letzten 3 Stellen enden auf 000");
  21.             }
  22.         else if (First3Eq1) {
  23.             System.out.println("Die ersten 3 Stellen beginnen mit 111");
  24.             }
  25.         else if (Last3Eq011 || Last3Eq001 || Last3Eq010 || Last3Eq101) {
  26.             System.out.println("Die letzten 3 Stellen enden mit 011, 001, 010 oder 101");
  27.             }
  28.         else {
  29.             System.out.println("Keine der gefragten Varianten lag vor!");
  30.         }
  31.         System.out.println("Die Zahl war: "+ Bit);
  32.         System.out.println("Die Binärzahl ist: " +Bin);
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement