Write a Java program that reads four integers and prints "two pairs" if the input consists of two matching pairs (in some order) and "not two pairs" otherwise.
For example,
1 2 2 1 two pairs
1 2 2 3 not two pairs
2 2 2 2 two pairs
PROGRAM:
import java.util.*;
public class twopairs
{
public static void main(String[] args)
{
Scanner num = new Scanner(System.in);
System.out.println("Enter four numbers: ");
int p = num.nextInt();
int q = num.nextInt();
int r = num.nextInt();
int s = num.nextInt();
if((p==q && r == s)|| (p==r && q==s) ||
(r==q && p==s))
{
System.out.println(p+" "+q+" "+r+" "+s+" two pairs" );
}
else
{
System.out.println(p+" "+q+" "+r+" "+s+" not two pairs");
}
}
}
OUTPUT:
Write a Java program that reads four integers and prints "two pairs" if the input consists...
JAVA. Write a program that reads in a series of positive integers and prints out the maximum value entered. The user will indicate they are finished entering numbers by entering zero or a negative integer.
C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...
Write a Java program that reads 10 integers from the keyboard and outputs all the pairs whose sum is 30 .
Write a program that reads 2 doubles, 2 float, and 4 integers and prints them four in a line separated by tabs or spaces. The user should be prompted for input with a suitable instruction and the output should line up to the right. The numerical output should also have a minimum width of 5 and a precision of 2 decimal places to the right of the decimal. In C programming
Write a Java program that reads a 1D array of integers from standard input and returns it.
Write a Java program that reads a word and prints its bigrams substrings. A character bigram is defined as a continuous sequence of two characters in a word. For example, if the user provides the input "rum", the program prints ru um Hint: 1. set two pointers, one always moves from the beginning of the string and the other moves from i+2, in which i is the current position of the first pointer. 2. print an error message if the...
IN PYTHONWrite a program that reads a list of integers in the range (0 – 49) and prints out the numbers that does not repeat twice.The first input of the program is the number of integers contained in this list, followed by the integers contained in the list. Print the numbers in in ascending order.Case 1:INPUT: 5 2 2 3 3 1OUTPUT:1Case 2:INPUT:6 1 2 1 2 2 2OUTPUT:2Case 3:INPUT:4 3 2 1 2OUTPUT: 1 3343 2 1 213
Write a program that reads a set of integers and then finds and prints the sum of the even and odd integers
C++ assignment Write a program that reads a sequence of integers and prints the following: 1. The number of odd and even numbers of inputs Use a sentinel value to signal the end of inputs. If the sentinel value is the first you enter, give a message “NO input is entered!”. Input Validation: Do not accept a negative number.
/*Write a Java program that generates 1000 random integers, * calculates the average and prints two counts, one for the * numbers lower than the average and one for the numbers larger than the average. */ Use java thanks