Prompts the user for a single integer value

Assignment Help Basic Computer Science
Reference no: EM132099029

Task 1. Make a Java class called Sequence which prompts the user for a single integer value called n, and reports the sequence of integers generated by the following rules, until1 the computed value becomes 1:

  • if n is even, the next value in the sequence is half of n if n is odd, the next value in the sequence is 3n+1

At the end of the program, the number of values in the sequence starting from the original n, and going to the value 1 should be reported, as shown below. If the user enters a value of n which is non-positive, then your program should simply output the message shown below in Sample 3 below and end.

Notes on spacing:

  • Each colon output by the program should be followed by a single space character.
  • Each value in the sequence output by your program should be followed by a single space,
  • including the final 1 value.
  • The Total number of values: line starts on a new line, and after the value is printed,
  • ends with a newline character.
  • The message The entered value was not positive., when needed, starts on a new
  • line, and ends with a newline character.
  • Here are three separate sample executions, with user input shown in bold:
  • SAMPLE 1
  • Please enter a positive starting value for n: 5 Sequence: 5 16 8 4 2 1
  • Total number of values: 6
  • SAMPLE 2
  • Please enter a positive starting value for n: 7 Sequence: 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 Total number of values: 17
  • SAMPLE 3
  • Please enter a positive starting value for n: -3 The entered value was not positive.

Reference no: EM132099029

Questions Cloud

Make a main method that will accomplish the steps : Make a main method that will accomplish the following steps. (You may assume that the class includes all appropriate setter methods and getter methods for all i
Make a setter method for the year attribute : Make an overloaded constructor for the Movie class that will accept a single argument for the title of the movie.
What is a single line of java code to make an object : 18. what is a single line of Java code to make an object called car from the Vehicle class. Assume the class has a default constructor.
What is aprogram that determines the english-language : For example, given an integer 1, return the string "one"; given an integer 2, return the string "two"; and so on, up through the integer 10.
Prompts the user for a single integer value : Task 1. Make a Java class called Sequence which prompts the user for a single integer value called n, and reports the sequence of integers generated
Define a class named hotdogstand : You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand's ID number
Prompt the user for two integers : Prompt the user for two integers, then accept the two integers from the user. Print a message that states whether or not the values are the same.
Determines if two values are the same : Make a method named compareValues that determines if two values are the same. The values are of type int. If the values are the same, return true; otherwise
Requirements of the following comment : Make a method that meets the requirements of the following comment.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Java programming class

Practice homework assignment. request assistance. for JAVA programming class, request commented

  What are the most important parts of dashboard

What is dashboard? What are the most important parts of dashboard?

  What kinds of problems do these updates fix

Microsoft offers "patches," or updates, for its Windows OS. Go to www.microsoft.com and search for the list of updates. What kinds of problems do these updates fix? Do you need any?

  How would a user perceive the mouse motion

Suppose that mouse position changes are being sent over the connection. Assuming that multiple position changes are sent each RTT, how would a user perceive the mouse motion with and without the Nagle algorithm?

  Too many sub menus can be confusing to the user

Too many sub menus can be confusing to the user? What are your thoughts in this? It is important to turn on security on the web server before deploying

  Sample output for the given program

Else, print "N : Lather and rinse." num_cycles times, where N is the cycle number, followed by "Done.". Sample output for the given program:

  Individuals pay the same marginal tax rate

All individuals pay the same marginal tax rate, regardless of income (a flat tax), and ii) there are no exemptions or deductions available when calculating taxable income. In a short essay (2-3 paragraphs) discuss the impact on equity (both types)..

  Master data and the importance of master data

Develop an informational handout which explains Master Data, the use of Master Data and the importance of Master Data.

  State the three steps of the boosting algorithm

State the three steps of the boosting algorithm.

  Discuss data conversion and changeover methods

Discuss data conversion and changeover methods as well as data conversion security and controls that are utilized during the systems implementation phase

  Legalizing marijuana

When California voted on legalizing marijuana, which side would you think that California beer distributors were on? What about snack food vendors? Why?

  Derive a radix-3 dit-fft algorithm for this case

Determine the total number of complex multiplications needed to implement the algorithm in part (b) above.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd