Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sharabaddin/0f5752ca57bf704b139215da4677082b to your computer and use it in GitHub Desktop.
Save Sharabaddin/0f5752ca57bf704b139215da4677082b to your computer and use it in GitHub Desktop.
import java.util.Arrays; //исключительно для быстрого вывода результата
public class HelloWorld{
public static void main(String []args){
// Call task 1
System.out.println("Task1: " + checkBinaryOne(100));
// Call task 2
int[] testArray = {
1, 2, 3,
};
System.out.println("Task2: " + Arrays.toString(reverseArray(testArray)));
}
//task1
public static int checkBinaryOne(int testDigit) {
int sum = 0;
String binaryText = Integer.toBinaryString(testDigit);
System.out.println("debug bin format:" + binaryText);
for (int i = 0; i < binaryText.length(); i++) {
if (binaryText.charAt(i) == '1') {
sum++;
}
}
return sum ;
}
//task1
public static int[] reverseArray(int[] array) {
int[] resultArray = new int[array.length];
for(int i = 0; i < array.length; i++) {
resultArray[i] = array[array.length - 1 - i];
}
return resultArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment