Hi,
Please find the below code.
There are comments on respective lines of code. These comments are used to understand the flow of the program.
// Program to check whether two strings are anagrams of
each other or not.
import java.io.*;
import java.util.*;
class Anagram{
static int number_of_chars = 256;
// function to check whether two strings
are anagram of each other
static boolean check(char s1[], char s2[])
{
// Create 2 count arrays and
initialize all values as 0
int count1[] = new
int[number_of_chars];
Arrays.fill(count1, 0);
int count2[] = new
int[number_of_chars];
Arrays.fill(count2, 0);
int i;
// For every character
in input strings, increment the count in the corresponding count
array
for (i = 0; i < str1.length
&& i < str2.length;
i++) {
count1[s1[i]]++;
count2[s2[i]]++;
}
// If both strings are
of different length then they are not called as anagrams.
if (s1.length != s2.length)
return
false;
// Compare count
arrays
for (i = 0; i < number_of_chars;
i++)
if (count1[i] !=
count2[i])
return false;
return true;
}
public static void main(String args[])
{
Scanner sc=new
Scanner(System.in);
System.out.println("Enter
Text1:");
String text1=sc.nextLine();
System.out.println("Enter
Text2:");
String text2=sc.nextLine();
System.out.println("Text
1:"+text1);
System.out.println("Text
2:"+text2);
char str1[] =
text1.toCharArray();
char str2[] =
text2.toCharArray();
if (check(str1, str2))
//calling the check method to check whether the two strings are
anagrams or not.
System.out.println("Anagram Found");
else
System.out.println("Anagram Not Found");
}
}
Hope this answers your question. If you liked the answer please give thumbs up and if you have any questions please ask in the comment section, I will try to solve them. Thank you.
Anagram Detector Due by Friday 12 April 2019 11:59 PM Program Overview: This program will be...
I need a program in fortran 95 that can detect if two strings are anagrams Anagram Detector Due by Friday 12 April 2019 11:59 PM Program Overview: This program will be able to determine if two inputted texts are anagrams of one another Relevant Details and Formulas: An anagram of a text is a rearrangement of the letters such that it forms another, usually intelligible, set of words. Capitalization is not important and any white space, punctuation, or other non-letter...
Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...
Program 3. Decisions Due: Friday, February 7 by 11:59 PM Overview For this program, design a wage calculator for a single user. The program will use the user's number of hours worked and their hourly wage to calculate: Gross Pay Deduction Net Pay The Gross Pay is the amount that the user is paid before any deduction is applied. The pay amount is based upon the number of hours worked. If 40 hours or less were worked, the gross pay...
Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...
14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...
Security is an important feature of information systems. Often, text is encrypted before being sent, and then decrypted upon receipt. We want to build a class (or several classes) encapsulating the concept of encryption. You will need to test that class with a client program where the main method is located. For this project, encrypting consists of translating each character into another character. For instance, if we consider the English alphabet, including characters a through z, each character is randomly...
I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...
6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
Assignment #6 - Arrays and Strings - Making random sentences! Due: Tuesday April 2, 11:59:00 pm Objective This assignment will consist of writing a program that involves practice with arrays, random number generation, and Strings. You may use c-strings or string objects here, however, string objects is recommended. Exercise Filename: sentences.cpp Write a program that uses random-number generation to create sentences. Create four arrays of strings (string objects highly suggested over c-strings) called article, noun, verb, and preposition. The arrays...