Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class clase {
- public static void main(String[] args) {
- numeros(//numero Cualquiera!
- }
- /**
- *
- * @param k
- */
- public static void numeros(long k) {
- System.out.print(k + ", ");
- while (k != 1) { // mientras k sea diferente de 1:
- // debo preguntar si k es par o impar
- if (k % 2 == 0) { // k es par:
- // k se debe dividir en 2
- k = k / 2;
- } else { // k es impar:
- // k se debe multiplicar por 3 y sumar 1
- k = k * 3 + 1;
- }
- System.out.print(k + ",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement