Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Java program that displays all 4-character strings on the screen in lexicographic order (also called dictionary order). It must display a string of
Write a Java program that displays all 4-character strings on the screen in lexicographic order (also called dictionary order). It must display a string of 4 characters per line. Only characters a, b, c, d are allowed within strings, but you can reuse the same character more than once within the same string. Within the same string, the character 'b' must always be immediately followed by the character 'a'. The same string cannot contain both the character 'd' and the character 'a'. Your program should end by displaying the number of character strings displayed on the screen. Your program receives nothing as input. Your program code must not include pre-calculated strings: it must generate them at runtime. Your program should not contain more than 200 short lines of code. Explain your solution. A work submitted without sufficient explanations may be assigned the score of zero, without right of resumption. You must justify all the qualifiers used (private, public, protected, static): you cannot use the keyword "static" without justifying it. There are several ways to resolve this problem. Perhaps the easiest way to do this is to have multiple nested loops. Hint: the result of your program must be the same on each execution. Hint: a character in Java has type char. Hint: a character string in Java has the type String. This guy is immutable. Hint: given a character string s, you can access the 3rd character with the syntax s [2]. Hint: you can create a character string from two characters c1 and c2 with the syntax Character.toString (c1) + Character.toString (c2). Hint: the total number of strings displayed is a mathematically determined value, it will be the same for all correct solutions to this problem. If the code of your solution is not valid Java, if it does not compile, a score of zero may be awarded. To successfully complete this course, you must be able to write functional and correct Java code. Comment: Some students have difficulty understanding the instruction: "the character' b "must always be immediately followed by the character caractre a '". You must be able to understand this logical constraint. For example, you shouldn't be wondering long if a string can end with the character 'b'. The response follows directly from the instruction
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started