Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

collatz conjecture

import java.util.Scanner;

public class CollatzConjecture {
    public static void main(String[] args){
        System.out.println("Enter a positive number");
        Scanner userInput = new Scanner(System.in);
        int n = userInput.nextInt();
           while (n!=1) {
               if (n % 2 == 0) {
                  n = n / 2;
               } else if (n % 2 == 1) {
                  n =3 * n + 1;
               }
           }
        System.out.println(n);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: android remove focus from an element 
Java :: compare two times in java 
Java :: How to efficiently shift a linked list by k positions, in Java? 
Java :: measure running time of a statement java 
Java :: requestmapping post 
Java :: check if a string is empty java 
Java :: android html to bitmap 
Java :: terminate a frame java 
Java :: Simple gui in java 
Java :: fill two dimensional array column by column java 
Java :: android application subclass 
Java :: hide element selenium 
Java :: hashmap to list java 
Java :: set source image in android studio 
Java :: java base64 
Java :: find maximum in array java 
Java :: java mockito any string import 
Java :: count occurrences of character in string java using hashmap 
Java :: how to import class from another file in java 
Java :: java throw keyword 
Java :: which api is android 12 
Java :: make edittext not editable android 
Java :: find java_home path in cmd 
Java :: polymorphism in oop 
Java :: java object to int 
Java :: comentario java 
Java :: java multiple catch blocks 
Java :: java set value of arraylist 
Java :: maven set java version 
Java :: java map merge example 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =