Question

Program must be written in Java. This program will read a text file that contains several...

Program must be written in Java.

This program will read a text file that contains several words and use a method to check if see any of the words are anagrams. If the words are anagrams then it will print out those words together. This program is a modification of this problem:

Two words are anagrams if they contain the same letters in the same
frequency. For instance, stale and least are anagrams of each other.
A simple way to check this is to sort the characters in each word; if
you get the same answer (in the example, we get aelst), the words are
anagrams of each other. Write a method that tests if two words are
anagrams of each other.

Sample Input: Dictionary.txt

a
aardvark
aardwolf
ab
aba
abaca
abacist
aback
abactinal
abacus
abaddon
abaft
abalienate
abalienation
abalone
abampere
abandon
abandoned
abandonment
abarticulation
abase
abased
abasement
abash
abashed
abashment
abasia
abasic
abate
abatement
abating
abatis
abatjour
abattis
abattoir
abaxial
abba
abbacy
abbatial
abbatical
abbatis
abbe
abbess
abbey
abbot
abbreviate
abbreviated
abbreviation
abbreviature
abc
abcoulomb
abdal
abderite
abdicable
abdicant
abdicate
abdication
abdicator
abditory
abditos
abdomen
abdominal
abdominocentesis
abdominoscope
abdominoscopy
abdominous
abdominousness
abdominovesical
abduce
abducent
abduct
abduction
abductive
abductor
abeam
abecedarian
abecedarius
abecedary
abed
abel
abelia
abelmoschus
abelmosk
abends
aber
aberdeen
aberdevine
aberrance
aberrant
aberration
abest
abet
abetalipoproteinemia
abetment
abettor
abeunt
abeyance
abeyant
abfarad
abhenry
abhor
abhorrence
abhorrent
abhorrer
abibis
abidance
abide
abiding
abidjan
abience
abient
abies
abigail
abiit
abilities
ability
abiogenesis
abiogenetic
abiogenist
abiotrophy
abito
abject
abjection
abjectly
abjectness
abjunction
abjuration
abjurationabjurement
abjure
abkari
ablactation
ablated
ablation
ablative
ablaut
ablaze
able
ablebodied
ablegate
ableism
ableness
ablepharia
ablepsia
ablepsy
abloom
ablude
ablution
ablutionary
abnaki
abnegation
abnegator
abnormal
abnormality
abnormalize
abnormally
abnormis
abnormity
abnormous
aboard
abocclusion
abode
abodement
aboding
abohm
aboideau
abois
aboiteau
abolengo
abolish
abolishable
abolishment
abolition
abolitionary
abolitionism
abolitionist
abolitionize
abomasal
abomasum
abominable
abominate
abomination
abominator
aborad
aboral
abord
aboriginal
aborigine
aborigines
aborning
abort
aborticide
abortifacient
abortion
abortionist
abortive
abortively
abortus
abound
abounding
about
abouts
above
aboveboard
aboveground
abovementioned
abovesaid
abovestairs
abra
abracadabra
abrachia
abrade
abraded
abrader
abraham
abramis
abranchiate
abrasion
abrasive
abreast
abrege
abreption
abridge
abridged
abridger
abridgment
abroach
abroad
abrocoma
abrocome
abrogate
abrogated
abrogation
abronia
abrupt
abruption
abruptly
abruptness
abruzzi
abscess
abscessed
abscind
abscision
abscissa
abscission
abscond
absconder
abscondment
absence
absens
absent
absentee
absenteeism
absently
absentminded
absentmindedness
absento
absents
absinth
absinthe
absolute
absolutely
absoluteness
absolution
absolutism
absolutist
absolve
absolved
absolver
absolvitory
absolvitur
absonant
absonous
absorb
absorbable
absorbate
absorbed
absorbefacient
absorbency
absorbent
absorber
absorbing
absorption
absorptivity
absquatulate
abstain
abstainer
abstemious
abstemiously
abstemiousness
abstention
absterge
abstergent
abstersion
abstersive
abstinence
abstinent
abstract
abstracted
abstractedly
abstractedness
abstraction
abstractionism
abstractionist
abstractive
abstractly
abstractness
abstractor
abstruse
abstrusely
absurd
absurdity
absurdly
absurdness
absurdum
abudefduf
abulia
abulic
abuna
abundance
abundant
abundanti
abundantly
abuse
abused
abuser
abusive
abusively
abut
abutilon
abutment
abuttal
abutter
abutting
abuzz
abvolt
abwatt
aby
abysm
abysmal
abyss
abyssal
abyssinian
ac
acacia
academia
academic
academical
academically
academician
academicianship
academist
academy
acadia
acadian
acalypha
acanthaceae
acanthisitta
acanthocephala
acanthocephalan
acanthocereus
acanthocybium
acanthocyte
acanthocytosis
acanthoid
acantholysis
acanthoma
acanthophis
acanthopterygii
acanthoscelides
acanthosis
acanthotic
acanthuridae
acanthurus
acanthus
acapnic
acapulco
acardia
acariasis
acariatre
acaricide
acarid
acaridae
acarina
acarine
acaritre
acarophobia
acarpelous
acarpous
acarus
acatalectic
acataphasia
acathexia
acathexis
acaudate
acaulescent
accedas
accede
accelerando
accelerate
accelerated
accelerating
acceleration
accelerative
accelerator
accelerometer
accension
accent
accented
accentor
accents
accentual
accentuate
accentuation
accept
accepta
acceptability
acceptable
acceptably
acceptance
acceptation
accepted
accepting
acception
acceptive
acceptor
access
accessible
accession
accessional
accessorial
accessory
acciaccatura
accidence
accident
accidental
accidentally
accidentalness
accidents
accipere
accipient
accipiter
accipitres
accipitridae
accipitriformes
accipitrine
acclaim
acclamate
acclamation
acclimatization
acclimatize
acclivitous
acclivity
acclivous
accloy
accolade
accommodate
accommodating
accommodation
accommodational
accommodative
accomodation
accompanied
accompaniment
accompanist
accompany
accompanying
accompli
accomplice
accomplish
accomplishable
accomplished
accomplishment
accomplishments
accompts
accord
accordance
accordant
accordian
according
accordingly
accordion
accordionist
accost
accouchement
accoucheur
accoucheuse
account
accountability
accountable
accountableness
accountancy
accountant
accountantship
accounter
accounting
accounts
accouple
accouplement
accousente
accouter
accoutered
accouterment
accouterments
accoy
accra
accredit
accreditation
accredited
accretion
accretionary
accretive
accrimination
accroach
accrue
accrued
accrust
accubation
accueil
accultural
acculturation
acculturational
accumbent
accumulate
accumulated
accumulation
accumulative
accuracy
accurate
accurately
accurse
accursed
accusable
accusation
accusative
accusatorial
accusatory
accuse
accused
accuser
accusing
accusingly
accustom
accustomary
accustomed
ace
acebutolol
aceite
aceldama
acentric
acephalia
acephalous
acequia
acequiador
acequiamadre
acer
aceraceae
acerate
aceration
acerb
acerbate
acerbic
acerbity
acerola
acervate
acervatim

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please give thumbs up, thanks

code:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
*
* @author VISHAL
*/
public class Anagrams {
public static void main(String[]args) throws FileNotFoundException
{
Scanner reader,keyboard;
String filename,temp;
keyboard=new Scanner(System.in);
System.out.println("Enter Filename : ");
filename=keyboard.nextLine();
reader=new Scanner(new File(filename));
ArrayList <String>Dictonary=new ArrayList();
ArrayList <String>SortedDictonary=new ArrayList();
while(reader.hasNext())
{
temp=reader.nextLine();
Dictonary.add(temp);
char tempArray[] = temp.toCharArray();
Arrays.sort(tempArray);
SortedDictonary.add(new String(tempArray));
}
for(int i=0; i<Dictonary.size(); i++)
{
for(int j=i+1; j<Dictonary.size(); j++)
{
if(SortedDictonary.get(i).equals(SortedDictonary.get(j)))
{
System.out.println(Dictonary.get(i)+" and "+Dictonary.get(j)+" are Anagrams ");
Dictonary.remove(j);
SortedDictonary.remove(j);
j--;
}
}
}
  
}
  
}

Add a comment
Know the answer?
Add Answer to:
Program must be written in Java. This program will read a text file that contains several...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT