


Program:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a string: ");
String strng = br.readLine();
int[][] matrx = new int[strng.length()][strng.length()];
for (int g = 0; g < matrx.length; g++) {
for (int i = 0, j = g; j < matrx[0].length; i++, j++) {
if (g == 0) {
matrx[i][j] = 1;
} else if (g == 1) {
matrx[i][j] = strng.charAt(i) == strng.charAt(j) ? 3 : 2;
} else {
if (strng.charAt(i) == strng.charAt(j)) {
matrx[i][j] = matrx[i + 1][j] + matrx[i][j - 1] + 1;
} else {
matrx[i][j] = matrx[i + 1][j] + matrx[i][j - 1] - matrx[i + 1][j - 1];
}
}
}
}
System.out.println(matrx[0][matrx[0].length - 1]);
}
}
Step by stepSolved in 2 steps with 2 images

- Write a program to check a string has uppercase character or not. the string must take from user. JAVAarrow_forwardIm stuck on this java code. The code is supposed to ask user for a string. Characters that are number, are doubled and replaced with the sum. The characters that are upper are replaced with lower and lower are replaced with upper. It should keep asking user for string until user input Q to end the program. example 1: original: 3rD converted: 6Rd ex 2: original: 6sJ converted: 3Sj (when a value is doubled and its than 9, the two digits are added. so 6 * 2 is 12. And then add the two digits. so 1 + 2 = 3.) I'm having problem with the code that its not reading where it replace the lower to upper and vice versa. this is my code so far: import java.util.Scanner;public class Convert {public static void main(String[] args) {Scanner input = new Scanner(System.in);String original, converted;while (true) {System.out.print("Original String (input):");original = input.nextLine();if (original.equals("q") || original.equals("Q")) {break;}char[] chars = original.toCharArray();for (int i = 0; i <…arrow_forwardWrite code to determine if the first character in an input string str is a lowercase character. If the first character is lowercase, output "issue", otherwise output "no problem". in javaarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





