Hacks
Hacks
import java.util.*;
public class Main {
public static void main(String[] args) {
//Scanner helps us to communicate with the machine and provide inputs.
Scanner sc = new Scanner(System.in);
System.out.println("Enter your first number");
int a = sc.nextInt();
System.out.println("Enter your second number");
int b = sc.nextInt();
Integer c = a + b;
System.out.println("Binary Result: " + Integer.toBinaryString(c));
}
}
Main.main(null);
import java.util.*;
class Yummy
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.Integer();
//Array that goes up to 100
int bin[]=new int[100];
//while n is greater than zero, we find the modulus repeatedly until n = 0
int i = 0;
while(n > 0)
{
bin[i++] = n%2;
n = n/2;
}
System.out.print("Binary number: ");
for(int j = i-1;j >= 0;j--)
{
System.out.print(bin[j]);
}
String output = Integer.toBinaryString(sum);
System.out.println(firstentry + " + " + secondentry + " = " + output);
}
}
public class IntByReference {
private int value;
public IntByReference(Integer value) {
this.value = value;
}
public String toString() {
return (String.format("%d", this.value));
}
public void swapToLowHighOrder(IntByReference i) {
if (this.value > i.value) {
int tmp = this.value;
this.value = i.value;
i.value = tmp;
}
}
public static void swapper(int n0, int n1) {
IntByReference a = new IntByReference(n0);
IntByReference b = new IntByReference(n1);
System.out.println("Before: " + a + " " + b);
a.swapToLowHighOrder(b); // conditionally build swap method to change values of a, b
System.out.println("After: " + a + " " + b);
System.out.println();
}
public static void main(String[] ags) {
IntByReference.swapper(21, 16);
IntByReference.swapper(16, 21);
IntByReference.swapper(16, -1);
}
}
IntByReference.main(null);