Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LongBit {
- public static void main(String[] args) {
- long Bit = 42;
- String Bin = Long.toBinaryString(Bit);
- boolean Last3Eq1 = Bin.endsWith( "111" );
- boolean Last3Eq0 = Bin.endsWith( "000" );
- boolean First3Eq1 = Bin.startsWith( "111" );
- boolean Last3Eq011 = Bin.endsWith( "011" );
- boolean Last3Eq001 = Bin.endsWith( "001" );
- boolean Last3Eq010 = Bin.endsWith( "010" );
- boolean Last3Eq101 = Bin.endsWith( "101" );
- if (Last3Eq1) {
- System.out.println("Die letzten 3 Stellen enden auf 111");
- }
- else if (Last3Eq0) {
- System.out.println("Die letzten 3 Stellen enden auf 000");
- }
- else if (First3Eq1) {
- System.out.println("Die ersten 3 Stellen beginnen mit 111");
- }
- else if (Last3Eq011 || Last3Eq001 || Last3Eq010 || Last3Eq101) {
- System.out.println("Die letzten 3 Stellen enden mit 011, 001, 010 oder 101");
- }
- else {
- System.out.println("Keine der gefragten Varianten lag vor!");
- }
- System.out.println("Die Zahl war: "+ Bit);
- System.out.println("Die Binärzahl ist: " +Bin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement