From e4e7fcc0a7c4df43ab805ceab5979164651462f3 Mon Sep 17 00:00:00 2001 From: Ankit Kumar <139707943+Kumar-Ankit07@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:42:52 +0530 Subject: [PATCH] solved Weird Question 82778 / 86630 --- Weird/even.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Weird/even.java diff --git a/Weird/even.java b/Weird/even.java new file mode 100644 index 0000000..9f6a2b1 --- /dev/null +++ b/Weird/even.java @@ -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); + + } + + } + } + +