Posts

Showing posts from March, 2019

possible palindrome or not

Write a java program to check that string is possible to make palindrome or not......... import java.util.Scanner; public class PossiblePalindrome { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter a String : "); String str=sc.nextLine(); char[] arr=str.toCharArray(); int[] index=indexNumber(arr); boolean res=possPalin(index); if(res) { System.out.println("yes it is possible to make palindrome"); } else { System.out.println("no it is not possible to make palindrome "); } } static int[] indexNumber(char[] arr) { int index[]=new int[26]; for(int i=0;i<arr.length;i++) { char ch=arr[i]; if(ch>64 && ch<91) { index[ch-65]++; } else if(ch>=97 && ch<=122) { index[ch-97]++; } } return index; } static boolean possPalin(int arr[]) { int count=0; fo

java program to Replace a Word in String

Write a java program to Replace a word in String : package String; import java.util.Scanner; public class ReplaceString { public static void main(String[] args) { Scanner in=new Scanner(System.in); String str="Hello <<UserName>>, How are you?"; String uname=null; do { System.out.println("Enter user name :"); uname=in.nextLine(); if(uname.length()>3 && uname.length()<11) break; else { System.out.println("Invalid user please ReEnter : "); continue; } }while(uname.length()<3 || uname.length()>10); System.out.println(uname); str=str.replaceAll("<<UserName>>", uname); System.out.println(str); } }