Core Java Programming Challenges #39 | Coding Challenges | Naresh IT

preview_player
Показать описание
Core Java Programming Challenges #39 | Coding Challenges | Naresh IT

💡 Also Watch

Java Programming Tutorials by Mr.Hari krishna:
Advanced Java Programming Tutorials by Mr.Nataraj:

Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.

💡 Visit Our Websites
#CoreJava_Programing #Challenges #CoreJava #Quiz
--------------------------

💡 About NareshIT:

"Naresh IT is having 14+ years of experience in software training industry and the best Software Training Institute for online training, classroom training, weekend training, corporate training of Hadoop, Salesforce, AWS, DevOps, Spark, Data Science, Python, Tableau, RPA , Java, C#.NET, ASP.NET, Oracle, Testing Tools, Silver light, Linq, SQL Server, Selenium, Android, iPhone, C Language, C++, PHP and Digital Marketing in USA, Hyderabad, Chennai and Vijayawada, Bangalore India which provides online training across all the locations

--------------------------

💡 Our Online Training Features:
🎈 Training with Real-Time Experts
🎈 Industry Specific Scenario’s
🎈 Flexible Timings
🎈 Soft Copy of Material
🎈 Share Videos of each and every session.

--------------------------

💡 Please write back to us at

--------------------------

💡 Check The Below Links

Рекомендации по теме
Комментарии
Автор

class Test
{
public static void main(String[] args)
{
int flag=0;
String s1="Army";
String s2="Mary";

char c1[]=s1.toCharArray();
char c2[]=s2.toCharArray();

{

for(int i=0;i<c1.length;i++)
{
for(int j=0;j<c2.length;j++)
{

{

flag++;

}
}

}
System.out.println(flag);
if(flag==c1.length)
{

System.out.println("Array having same elements");
}
else
{
System.out.println("Array are not having same elements");
}

}
else
{
System.out.println("Array are not equal in length or any of them are null");
}
}

}

sreedharkamera
Автор

Sort both string and convert to upper case and then compare

nisarpatel
Автор

//this works only when both the Strings have unique characters for checking if not it will tell both are not anagrams. EX: Test Test
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first string");
String str1 = sc.nextLine();
System.out.println("Enter the second string");
String str2 = sc.nextLine();
int count = 0;
char[] chars1 = str1.toCharArray();
char[] chars2 = str2.toCharArray();
if(chars1.length == chars2.length)
{
for(int i =0;i<chars1.length;i++)
{
if(chars1[i]>=65 && chars1[i]<=90)
{
chars1[i]+=32;
}
if(chars2[i]>=65 && chars2[i]<=90)
{
chars2[i]+=32;
}
}
count = 0;
for(int i =0;i<chars1.length;i++)
{

for(int j = 0;j<chars2.length;j++)
{




}

}


if(count==chars1.length)
{
System.out.println("both the strings are Anagrams");
}
else
{
System.out.println("both the strings are not Anagrams");
}
}
else
{
System.out.println("Since both the Strings are not of equal length both are not anagrams");
}



}

SunilKumarSunil
Автор

//check if two strings are anagrams or not (same characters or not)
// I suppose that the 2 strings have the same size, and no chars are duplicated
public class Challenge39 {
public static void main(String[] args) {

String str1 = "samh";
String str2 = "Sahw";

char[] str1Char = str1.toCharArray();
char[] str2Char = str2.toCharArray();

//convert all upper case to lower case
for(int i = 0; i<str1Char.length;i++){
if(str1Char[i]>=65 && str1Char[i]<=90){
str1Char[i] = (char) (str1Char[i]+32);
}
if(str2Char[i]>=65 && str2Char[i]<=90){
str2Char[i] = (char) (str2Char[i]+32);
}
}
int count = 0;
for(int i =0; i<str1Char.length;i++){
for(int j=0; j<str2Char.length;j++){
if(str1Char[i] == str2Char[j])
count++;
}
}
if(count == str1Char.length)
System.out.println("The 2 strings are anagrams");
else
System.out.println("The 2 strings are not anagrams");
}
}

samahmahdi
Автор

public class CodeChallenge39_anigram {
public static void main(String[] args) {
String s1="Army";
String s2="Mary";
StringBuilder sb= new StringBuilder();
boolean areMatching=false;
char c1[]= s1.toCharArray();
char c2[]= s2.toCharArray();
String ss1 = convertIntoSb(c1);
String ss2 = convertIntoSb(c2);
if(ss1.length() != ss2.length()){
System.out.println(ss1 + " and "+ ss2 + " aren't anagram");
}
else {
for(int x=0;x<ss1.length();x++){
areMatching=false;
for(int y=0;y<ss2.length();y++){
if(isCharEquivalente(ss1.charAt(x), ss2.charAt(y))){
areMatching = true;
break;
}
else{
areMatching = false;
continue;
}
}
if(areMatching){
continue;
}
else{
break;
}
}
if(areMatching){
System.out.println(ss1 + " and "+ ss2 + " are anagram");
}
else{
System.out.println(ss1 + " and "+ ss2 + " aren't anagram");
}
}
}
private static boolean isCharEquivalente(char charOut, char charIn) {
if(charOut>=97){
charOut=(char) (charOut -32);
}
if(charIn >=97){
charIn = (char) (charIn -32);
}
return charOut==charIn;
}
private static String convertIntoSb(char[] c1) {
StringBuilder sbl = new StringBuilder();
for(int i=0;i<c1.length;i++){
if((c1[i]>=65 && c1[i]<=90) || (c1[i]>=97 && c1[i]<=122)){
sbl.append(c1[i]);
}
}
return sbl.toString();
}
}

itisdawit