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
san4es73 [151]
3 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]3 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
How to connect apple pencil 2 to ipad 8th generation?
stepladder [879]

Answer:

That pencil doesn't adjust to that ipad because those two aren't compatible

Explanation:

5 0
2 years ago
Which of these Logic Statement's are correct for the following diagram? *
Solnce55 [7]

Answer:

A AND B OR C

Explanation:

7 0
2 years ago
What is the name of the function below?<br><br> function go(){<br> alert("hello everybody");<br> }
labwork [276]

Answer:

It’s Java script I think and it makes something say hello everybody

Explanation:

6 0
3 years ago
Which of the following code correctly registers a handler with a button btOK?a. btOK.setOnAction(e -&gt; System.out.println("Han
Bad White [126]

Answer:

The correct answer is C:

btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event"));

Explanation:

The button produces an action once clicked. The setOnAction method indicates what will happen when the button is clicked. Action Event is a type of event that gets processed by EventHandler, which provides the action to be performed by clicking the button (printing out "Handle the event").

4 0
3 years ago
How is geeking out related to the concept of social capital?
vodka [1.7K]

Answer:

It relates to social relationships and social structures. It involves people knowing each other and having positive relationships based on trust, respect, kindness, ect.

Explanation:

3 0
2 years ago
Other questions:
  • Assume that isIsosceles is a bool variable, and that the variables isoCount, triangleCount, and polygonCount have all been decla
    11·1 answer
  • Jeremy’s office is in an earthquake prone area. His web server is in his office. What step should he take to protect the data on
    5·1 answer
  • Megan has written the following rough draft for her assignment. Choose the correct way to complete each sentence. Sarah is creat
    13·1 answer
  • What advantage does a circuit-switched network have over a packet-switched network? What advantages does TDM have over FDM in a
    6·1 answer
  • How is the internet made?
    7·1 answer
  • Which type of security software prevents, detects, and removes the malware program that tries to collect personal information or
    8·2 answers
  • PLEASE HELP ASAP<br> Which technology encrypts traffic between a web browser and a website?
    10·2 answers
  • Which of the following is NOT areserved word in Java?intpublicstaticnum
    9·1 answer
  • Which of the following are causes of a run-time error. Choose all that apply.
    13·1 answer
  • What does business informWhat does business information management do?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!