I am taking an introductory programming course and need a bit of help. The assignment is to have the Java program read a message (I am assuming from a .dat file, not quite sure). The program creates substitutes each random letter with a different letter chosen at random by the computer. If the letter M is chosen to replace the letter P in the message, then M replaces P in every instance of the message.
Right now, I just need help with generating a set of the 26 letters ordered randomly without duplicates. Here is what I have:
Right now the program does nothing. If I remove the last for loop with j as the counter and everything within that for loop, I get an output of 26 letters randomly chosen, but there are duplicates. The last for loop is supposed to say something like, "If the randomly generated letter (substitute) has appeared before in substitute[], then generate a new random number until it is no longer a duplicate of a previous number, at which point the letter which corresponds to the random number is stored in substitute.
So if you could give me some suggestions it would be much appreciated. If I am overcomplicating things and there is a much easier way to do this, please guide me in the right direction.
Thanks,
Noah
EDIT: Spacing in the program code isn't working. Looks fine while I'm editing it though. What's wrong?
EDIT 2: See here for my code, correctly formatted.
Any Video Converter Free 9.2.3 by Razvan Serea
Any Video Converter is an All-in-One video converting tool with an easy-to-use graphical interface, fast converting speed and excellent video quality. Any Video Converter supports all popular video formats and converts your videos to different video formats including MP4, MOV, MKV, M2TS, M4V, MPEG, AVI, WMV, ASF, OGV, WEBM, and more. It supports converting videos to customized percent (50%, 100%, 200%, and more) or resolution (480p, 720p, 1080p, 4K, and more); It supports encoding videos into x264, x265, h263p, xvid, mpeg, wmv, and more.
Any Video Converter Free key features:
Compatible with Windows 11/10/8.1/8/7 (32-64bit)
User interface are available in 14 languages
Convert all kinds of video formats including high-definition videos
Extract audio from any videos and save as MP3/WMA for your mp3 player
Take snapshot from any videos and build your own picture collection
Support high-definition for both input and output
Batch add videos from hard drive and batch convert
Customize output parameters completely as you like
Manage your output videos files by group or output profile
Merge several video files into a single and long one
Clip a video into segments
Free Audio Filter: Adjust audio volume and add audio effects
Crop frame size to remove black bars and retain what you want only
Adjust the brightness, contrast, saturation
Rotate or flip or add noise/sharpen effects
Produce output video with subtitles of your own dialogue
and much, much more...
Any Video Converter Free 9.2.3 changelog:
Fixed video download engine auto-update failures.
Added custom speed control support in the speed change tool.
Added support for downloading YouTube AI-generated subtitles.
Added support for preserving original audio stream in the format convert tool (e.g., Dolby Atmos, DTS:X).
Fixed other bugs and improved overall performance.
Download: Any Video Converter Free 9.2.3 | 7.6 MB (Freeware)
View: Any Video Converter Free Home Page | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
Not sure what country you’re in but in many countries you can absolutely jail the sellers behind businesses… in fact I’d say in most countries you can do that
I hate Slack, but Teams is much worse - maybe they've already optimized it, but it was a huge slog the last time I've checked about half a year ago. I miss my Skype.
Question
-Noah-
Hi guys,
I am taking an introductory programming course and need a bit of help. The assignment is to have the Java program read a message (I am assuming from a .dat file, not quite sure). The program creates substitutes each random letter with a different letter chosen at random by the computer. If the letter M is chosen to replace the letter P in the message, then M replaces P in every instance of the message.
Right now, I just need help with generating a set of the 26 letters ordered randomly without duplicates. Here is what I have:
Right now the program does nothing. If I remove the last for loop with j as the counter and everything within that for loop, I get an output of 26 letters randomly chosen, but there are duplicates. The last for loop is supposed to say something like, "If the randomly generated letter (substitute) has appeared before in substitute[], then generate a new random number until it is no longer a duplicate of a previous number, at which point the letter which corresponds to the random number is stored in substitute.
So if you could give me some suggestions it would be much appreciated. If I am overcomplicating things and there is a much easier way to do this, please guide me in the right direction.
Thanks,
Noah
EDIT: Spacing in the program code isn't working. Looks fine while I'm editing it though. What's wrong?
EDIT 2: See here for my code, correctly formatted.
Edited by -Noah-Link to comment
https://www.neowin.net/forum/topic/776712-java-generate-the-alphabet-in-random-order-no-duplicates/Share on other sites
32 answers to this question
Recommended Posts