For my assignment I have to write and test a Java program, as long as the blank line is read several lines of input Have to be read in After reading each line, I have to decide that there is a palindrome in the line and if there is a pallogram in it, then I have to print it to see what type of pandidrum it is (word, phrase, or number). To run Palindrome I have to use a pseudo-code.
Pseudo code is:
Note: In the following, the symbol represents the assignment
left 0
in the correct in string The last letter position
OK true
OK and left & lt;
< / P>
Convert both ch1 and ch2 to upper case
if ch1 = ch2
Returns OK
What do I have so far:
Import java.util.Scanner ; Public square project4 {public static zero main (string [] args) {string line = getInputLine (); While (IsEmptyLine (line)) {ifIlland (line) is System.out.println ("\" "+++" \ "is a payroll and a + + + papeltype (line)); Else System Out.println ("\" "+ line +" \ "is not a palindrome"); line = getInputLine ();} System.out.println ("end of program");} public static string getInputLine () {System .out.println ("Enter a line of input:"); scanner = new scanner (System.in); string line = in.next (); Println (line); return line;} public static boolean actinine (string Str) {boolean is actuall Eine; if (str == faucet) isEmptyLine = true; rest is apertyle = false; return true;} public stable boolean isPalindrome (string str) {scanner word = new scanner (System.in); string isPalindrome = word.next ( ); Int strLength = isPalindrome.length (); while (true & amp; amp; l; l; isPalindrome.charAt (isPalindrome.length () -1)) {if (Character.isDigit (strLength }}. Character [ I have not finished it but I need help with understanding the use of pseudo code. First of all if I do not understand the part of the statement. If someone has time to explain the code, then I appreciate it.
The best approach I've found is to understand the phonetic code, by starting any code First, go through it using a piece of paper. Write something like "ABCDCABA"
Use your left and right indicator fingers to track the barracks and left variables you will start with the leftmost finger on the left, and your right to the last character is just now Take steps through instructions.
The basic idea is to compare the letter on the left side to the right, if it is the same, move from left to right, and move one position on the left to the left.
You will leave any non-alphanumeric characters on the way. To avoid the sensitivity of any case the characters are also converted into upper-case.
If at any time the character on the left does not match the right side of the character, then we do not have a pendulum. If left and right meet, or pass each other, and everything has been a match till that point, then we have one.
Since you first asked about the statement, know that the character class of Java is
public static boolean is letterarit (four f)
You can use:
if (! Character.isLetterOrDigit Ch1)) {...
as a side note In, your EmptyLine () method always gives the correct method the whole method should be rewritten:
Public stable boolean is EmptyLine (string str) {return (str == null); }
And for that matter, the method can be completely removed, and simply rewrite the loop of your time:
while (Line! = Null) {
No comments:
Post a Comment