Question: ## Problem Description You are to write a program that will take one string of four positive, single-digit integers (e.g. 0 1 1 2) and

## Problem Description

You are to write a program that will take one string of four positive, single-digit integers (e.g. "0 1 1 2") and will test to see if there are two pairs present in the string. This will be implemented by the **IntegerPairs** object. This object will have a constructor that takes no arguments and the following two methods:

- ```java

public void setPairString(String str)

```

- This method will take a string as an argument and then store it in an instance variable.

- ```java

public boolean hasTwoPairs()

```

- This will return true when there are only two pairs present in the string.

Hints:

- You can use a **Scanner** on a string as well as **System.in**. It works the same way but the constructor takes a string rather than **System.in**.

- After you are done with the scanner be sure to call **{your scanner variable name}.close()**;

- Don't be afraid to make local variables. You can use them to hold the numbers you get from the string.

- You do NOT need nested ifs and you definitely do NOT need loops to solve this

- Think about using the && (logical and) operator to test conditions

- Depending on what method you use to convert strings (e.g. Integer.parseInt), you may want to use an try...catch block (covered in class) to handle a parsing exception. See the Java API documentation for what type of exception an the parseInt method throws

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!