answer.
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
san4es73 [151]
2 years ago
10

Consider an array inarr containing atleast two non-zero unique positive integers. Identify and print, outnum, the number of uniq

ue pairs that can be identified from inarr such that the two integers in the pair when concatenated, results in a palindrome. If no such pairs can be identified, print -1.Input format:Read the array inarr with the elements separated by ,Read the input from the standard input streamOutput format;Print outnum or -1 accordinglyPrint the output to the standard output stream
Computers and Technology
1 answer:
Delvig [45]2 years ago
3 0

Answer:

Program.java  

import java.util.Scanner;  

public class Program {  

   public static boolean isPalindrome(String str){

       int start = 0, end = str.length()-1;

       while (start < end){

           if(str.charAt(start) != str.charAt(end)){

               return false;

           }

           start++;

           end--;

       }

       return true;

   }  

   public static int countPalindromePairs(String[] inarr){

       int count = 0;

       for(int i=0; i<inarr.length; i++){

           for(int j=i+1; j<inarr.length; j++){

               StringBuilder sb = new StringBuilder();

               sb.append(inarr[i]).append(inarr[j]);

               if(isPalindrome(sb.toString())){

                   count++;

               }

           }

       }

       return count == 0 ? -1 : count;

   }

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       String line = sc.next();

       String[] inarr = line.split(",");

       int count = countPalindromePairs(inarr);

       System.out.println("RESULT: "+count);

   }

}

Explanation:

OUTPUT:

You might be interested in
You are using a polynomial time 2-approximation algorithm to find a tour t for the metric traveling salesman problem. Which of t
Svet_ta [14]

Answer:

B. The cost of tour t is at most twice the cost of the optimal tour.

Explanation:

You are using a polynomial time 2-approximation algorithm to find a tour t for the traveling salesman problem.

The cost of tour t is at most twice the cost of the optimal tour

The equation represented as Cost(t) <= 2 Cost(T)

Where

Cost (t) represents cost of tour t

Cost(T) represents cost of the optimal tour

3 0
2 years ago
Janice is unsure about her future career path she has grown up on her family farm but she is also interested in medicine Janice
KiRa [710]
Janice can actually used both knowledge as an advantage. She can use her background in farming while learning more about medicine. In such a way, she can have a strong advantage in medicinal farming - like learn ways to create good and effective drugs from plants, etc. 
5 0
2 years ago
Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", output is:9_Hint: Use two if
Mashcka [7]

Answer:

Following is given the code as required.

I hope it will help you!

Explanation:

7 0
2 years ago
Mary has been locked out of her account after failing to correctly enter her password three times. As the system administrator,
Digiron [165]
Oh hey lol yea yea lol I got the money back to me put on the phone so you know
7 0
2 years ago
Your friends credit scores are 560, 675, 710, 590, and 640. Your credit score is 680. What is the difference between the average
Wittaler [7]

Answer:

560+675+710+590+640=3175/5=635

so your credit score is 45 credits better than the average of your friends

Explanation:

3 0
2 years ago
Other questions:
  • Wesley has to create a web banner to announce a “Back to School” sale by an online retailer. Which information should he determi
    15·2 answers
  • In what year were graphical user interfaces (GUIs) pioneered? 1969 1974 1991 2001
    12·2 answers
  • Ivan has five workbooks open. He has arranged these files in a specific grouping so he can view them at the same time. In order
    10·1 answer
  • 3.5 Code Practice
    11·2 answers
  • You have several pictures of different sizes that you would like to frame.A local picture framing store offers two types of fram
    15·1 answer
  • Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algo
    11·1 answer
  • What types of messages flow across an SDN controller’s northbound and southbound APIs? Who is the recipient of these messages se
    15·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • Which of the given assertion methods will return true for the code given below? Student student1 = new Student(); Student studen
    9·1 answer
  • A retailer is able to track which products draw the most attention from its customers through the use of 5g-enabled motion senso
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!