Question

Leur that repest a Post ve integer as pipit te the number is even, suide it by 2 tt not, mutip the wmber by 3 and then add t Repaat ts poces wth the resuling number and tomtne rependhng onil the 1 Heached the 土 ls reached, e program should display 丬he number of iterations repind 40each tke number 1 When the pgmam reperts inpot, tshaul check thai the user lpuis a posergaer Han A. f o an emer messa ge should be genenaled.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
public class Test {
   public static void main(String args[]){
       Scanner keyboard = new Scanner(System.in);
       System.out.println("enter an integer");
       int i = 0;
       int num = keyboard.nextInt();
       if (num<=1)
           System.out.println("Error: Number is less than or equal to 1");
       else
           while(num!=1){ ++i;
               if(num%2==0)
                   num=num/2;
               else
                   num = num * 3 + 1;
           }
       System.out.println(i + " Number of Iterations");
   }

}

Screenshot

Problems Javadoc Declarat terminated> Test Java Application] C: enter an integer Number of Iterations

Add a comment
Know the answer?
Add Answer to:
Leur that repest a Post ve integer as pipit te the number is even, suide it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT