Write a java program to validate a string

Write a java program to validate a string. Write a program to read two strings and check whether or not they have dashes in the same places. Print “Yes” if the condition satisfies, else print “No”.

The return type (Integer) should return 1 if all dashes are placed correctly, else return 2.

Note: The strings must have exactly the same number of dashes in exactly the same positions. The strings might be of different length.

Input and Output Format:

Input consists of two strings.

Output consists of a string (“Yes” or “No”).

Refer sample output for formatting specifications.

Sample Input 1:



Sample Output 1:


Sample Input 2:



Sample Output 2:


java program to validate a string

package com.demo;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
String s2 = sc.nextLine();
getvalues(s1, s2);
public static void getvalues(String s1, String s2) {
ArrayList<Integer> l1 = new ArrayList<Integer>();
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) == '-') {
ArrayList<Integer> l2 = new ArrayList<Integer>();
for (int i = 0; i < s2.length(); i++) {
if (s2.charAt(i) == '-') {
if (l1.equals(l2)) {
} else


Add a Comment

Your email address will not be published. Required fields are marked *

fourteen − 1 =