Given a number n between 1 and 12 (inclusive), your job is to find all the pairs of numbers that produce n when summed. For instance, given the number 5, two possible pairs of numbers are1, 4
and 2, 3
. Each number in the pair must be unique, meaning that 3, 3
is not a valid pair to sum to 6.
You will be writing a method to accomplish this goal.
Your method will take as a parameter the integer n to find sums of.
Your method should return a String containing all of the pairs of numbers that sum to n. If there are no such pairs, you should return the String “NONE”.
You should also fill in the main
method to test the sumOfPairs()
method.
Your main
method should get user input, then call the method with the value retrieved. The user shouldn’t be allowed to enter a number outside of the available range (1 - 12 inclusive). Your program should continue asking for input until the user enters 0.
Enter a number between 1 and 12 inclusive (0 to quit): 2 Pairs for 2: NONE Enter a number between 1 and 12 inclusive (0 to quit): 3 Pairs for 3: 1 2 Enter a number between 1 and 12 inclusive (0 to quit): 5 Pairs for 5: 1 4, 2 3 Enter a number between 1 and 12 inclusive (0 to quit): 15 Out of range, try again! Enter a number between 1 and 12 inclusive (0 to quit): 0
Sum of PairsProblemGiven a number n between 1 and 12 (inclusive), your job is to find all the pairs of numbers that produce n when summed. For instance, given the number 5, two possible pairs of numbers are1, 4 and 2, 3. Each number in the pair must be unique, meaning that 3, 3 is not a valid pair to sum to 6.You will be writing a method to accomplish this goal.sumOfPairs()Your method will take as a parameter the integer ...
Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...
Write a program using M.I.P.S that asks user “how many positive number that is devisable by 6 you want to add?” .Then your loopcounter would be the user input. If the user enters a positive number between 1 and 100 that is devisable by 6, you increment your loop counter and add it to the sum.. You need to decide if the positive number entered by the user is divisible by 6 or not. Your program should print an error...
We use JAVA. Thanks. Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....
use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...
import java.util.*; public class PairFinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Read in the value of k int k = Integer.parseInt(sc.nextLine()); // Read in the list of numbers int[] numbers; String input = sc.nextLine(); if (input.equals("")) { numbers = new int[0]; } else { String[] numberStrings = input.split(" "); numbers = new int[numberStrings.length]; for (int i = 0; i < numberStrings.length; i++) { numbers[i] = Integer.parseInt(numberStrings[i]); } } System.out.println(findPairs(numbers, k)); } //method that...
Loops | Methods | Arrays(programming language java) in software (ATOM) Write a toolkit that includes some common functions a user might want or need An encryption/ decryption method. Both methods should take in a String (the String that needs to be changed), and an encryption value. The methods need to change the String by the value Write a method that takes an integer array as an argument. The method should return the sum of all of the elements Write a...
The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...
This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...