I need to do a program that does the following:
• Start with an integer N
• If N is even, divide by 2;
• If N is odd, multiply by 3 and add 1;
• Repeat this new process with the new value of N, if N ≠ 1;
• Ends the process when N = 1.
Scanner NUM = new Scanner(System.in);
double numerox;
System.out.println("Digite um numero inteiro: ");
double NUM1 = NUM.nextDouble();
while ((NUM1 % 2 == 0) && (NUM1 != 1))
{
numerox = NUM1 * 2;
System.out.println(+numerox);
break;
I just did it.
What can I do to create a variable that stores these numbers and then print them and show their sum?
I thought about creating a variable NUMX
but I do not know if it will work.