1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pshichka [43]
3 years ago
11

Change the Towers of Hanoi program so that it does the following: a)Counts the number of ring moves and prints that - instead of

the sequence of the moves. Use a static variable count of type int to hold the number of moves. b)Repeatedly prompts the user for the number of rings and reports the results, until the user enters a number less than 0
Computers and Technology
1 answer:
aniked [119]3 years ago
8 0

Answer:

Following are the program in the Java Programming Language.

//import scanner class package

import java.util.Scanner;

//define class

public class Tower_of_Hanoi {

//define static integer variable

public static int count = 0;

//define function

public static void Permute_Arrange(int n, char x, char ax, char to) {

//set if statement

if (n == 1) {

//increament in count by 1

++count;

}

//otherwise  

else  

{

Permute_Arrange(n - 1, x, to, ax);

++count;

Permute_Arrange(n - 1, ax, x, to);

}

}

//define main function

public static void main(String[] args)  

{

//set scanner type object

Scanner sc = new Scanner(System.in);

//print message

System.out.println("Enter less than 0 to exit");

//set the while infinite loop

while(true)

{

//print message

System.out.print("Enter the number of Disks: ");

//get input from the user

int num_of_disk = sc.nextInt();

//set the if statement to break the loop

if(num_of_disk<0)

{

//exit from the loop

System.exit(0);

}

//call the function

Permute_Arrange(num_of_disk, 'A', 'B', 'C');

//print message with output

System.out.println("Total number of Disc Moves is: " + count);

count = 0;

}

}

}

<u>Output:</u>

Enter less than 0 to exit

Enter the number of Disks: 4

Total number of Disc Moves is: 15

Enter the number of Disks: 7

Total number of Disc Moves is: 127

Enter the number of Disks: -1

Explanation:

Here, we define a class named "Tower_of_Hanoi"

  • Set the integer data type static variable "count" and initialize the value to 0.
  • Define void data type static function "Permute_Arrange" and pass three characters type arguments "x", "ax", and to and one integer type argument "n", inside it we set if condition to increment in the count variable otherwise call the function.
  • Finally, we define the main function to get input from the user and pass the argument list in function and call the function.
You might be interested in
'|'/2`/ '|'[] |)[-([]|)[- '|'#!$
natita [175]

Answer: mr Man

Explanation:

7 0
3 years ago
What Are the Components of a Web Address? *​
ipn [44]

Answer:

What Are the Components of a Web Address?

1.Protocol. The first component of a web address is the protocol, which is also known as the scheme. ...

2.Domain Name. The domain name part of the web address is the unique identifier for the website on the internet. ...

3.Domain Extension. ...

4.Path & Filename.

5 0
3 years ago
Read 2 more answers
The three Fs of product design are form, fit and
Rudiy27

Answer: Function

Explanation: <em>"Function is a criterion that is met when the part performs its stated purpose effectively and reliably. In an electronics product, for example, function can depend on the solid-state components used, the software or firmware, and quite often on the features of the electronics enclosure selected. Poorly placed or sized ports and misleading or missing labeling are two of the most common ways in which an enclosure can fail the function criterion."</em>

5 0
3 years ago
Read 2 more answers
Why backup system of data and software is necessary. ​
zavuch27 [327]

Answer:

The purpose of the backup is to create a copy of data that can be recovered in the event of a primary data failure. Primary data failures can be the result of hardware or software failure, data corruption, or a human-caused event, such as a malicious attack (virus or malware), or accidental deletion of data.

7 0
3 years ago
Which of the following is not considered a flow in supply chains?
kramer
I don’t know if this helps, but here are three types of main flows: flow of material/goods, flow of money/cash, and flow of information.
5 0
2 years ago
Other questions:
  • What is an (CR) Optical character recognition?
    13·2 answers
  • The _____ establishes that the destination device is present on the network, verifies active service, and informs the destinatio
    13·1 answer
  • What is a flash player?
    9·2 answers
  • Please answer this I know that no one else does but I can't think right now
    10·1 answer
  • I need urgent help. which of these network has minimum data loss. a. LAN b. MAN c. WAN ​
    11·1 answer
  • Your windows system is used by several people, so you want increase security by requiring users to create passwords that are at
    9·1 answer
  • Word templates include pre-made flyers which may be edited and saved only if permission is obtained from the Microsoft Office te
    11·1 answer
  • February 1995, Kevin Mitnick was arrested. While on parole was he allowed to have a phone or computer?
    6·2 answers
  • Unit 2: Lesson 6 - Coding Activity 1
    10·1 answer
  • Hosts on the Internet have ________ addresses. Group of answer choices both A and B neither A nor B IP data link
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!