Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved Weird Question 82778 / 86630 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Weird/even.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Weird;

import java.util.Scanner;

public class even {

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// 82778 / 86630
// Consider an algorithm that takes as input a positive integer
// n n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for
// n = 3
int n;
System.out.println("Enter the Value of n : ");
n = sc.nextInt();
for (int i = 1; i< n ;) {

if(n % 2 == 1)
{
n = n * 3 + 1;


}
else {

n = n/2;

}
System.out.println("Value of n = "+ n);

}

}
}