The palindrome checker works perfectly. However, l want to know how can l add co
ID: 3620703 • Letter: T
Question
The palindrome checker works perfectly. However, l want to know how can l add code which allows me to assume that the user has entered a string of some arbitrary length (1 or more characters). By the way, l only have to make this assumption if the user has not entered the sentinel value Done for the program to quit. import javax.swing.*;public class practiseassignment
{ public static void main ( String [] args )
{ String input; int mid; int length;
input=JOptionPane.showInputDialog("Enter a palindrome");
length = input.length();
System.out.println("The length is " + length);
mid = length/2+1;
System.out.println("The mid is " + mid);
for(int count =0;count<mid;count++) { if ( (input.charAt(count))==input.charAt(length-1-count)) { if(input.charAt(count)==input.charAt(mid)) { System.out.println("It is a palindrome"); } }
}
}
}
The palindrome checker works perfectly. However, l want to know how can l add code which allows me to assume that the user has entered a string of some arbitrary length (1 or more characters). By the way, l only have to make this assumption if the user has not entered the sentinel value Done for the program to quit. import javax.swing.*;
public class practiseassignment
{ public static void main ( String [] args )
{ String input; int mid; int length;
input=JOptionPane.showInputDialog("Enter a palindrome");
length = input.length();
System.out.println("The length is " + length);
mid = length/2+1;
System.out.println("The mid is " + mid);
for(int count =0;count<mid;count++) { if ( (input.charAt(count))==input.charAt(length-1-count)) { if(input.charAt(count)==input.charAt(mid)) { System.out.println("It is a palindrome"); } }
}
}
}
The palindrome checker works perfectly. However, l want to know how can l add code which allows me to assume that the user has entered a string of some arbitrary length (1 or more characters). By the way, l only have to make this assumption if the user has not entered the sentinel value Done for the program to quit. import javax.swing.*;
public class practiseassignment
{ public static void main ( String [] args )
{ String input; int mid; int length;
input=JOptionPane.showInputDialog("Enter a palindrome");
length = input.length();
System.out.println("The length is " + length);
mid = length/2+1;
System.out.println("The mid is " + mid);
for(int count =0;count<mid;count++) { if ( (input.charAt(count))==input.charAt(length-1-count)) { if(input.charAt(count)==input.charAt(mid)) { System.out.println("It is a palindrome"); } }
}
}
}
The palindrome checker works perfectly. However, l want to know how can l add code which allows me to assume that the user has entered a string of some arbitrary length (1 or more characters). By the way, l only have to make this assumption if the user has not entered the sentinel value Done for the program to quit. import javax.swing.*;
public class practiseassignment
{ public static void main ( String [] args )
{ String input; int mid; int length;
input=JOptionPane.showInputDialog("Enter a palindrome");
length = input.length();
System.out.println("The length is " + length);
mid = length/2+1;
System.out.println("The mid is " + mid);
for(int count =0;count<mid;count++) { if ( (input.charAt(count))==input.charAt(length-1-count)) { if(input.charAt(count)==input.charAt(mid)) { System.out.println("It is a palindrome"); } }
}
}
}
Explanation / Answer
import javax.swing.*; public class practiseassignment { public static void main ( String [] args ) { String input; int mid; int length; try { input=JOptionPane.showInputDialog("Enter a palindrome"); length = input.length(); System.out.println("The length is " + length); mid = length/2+1; System.out.println("The mid is " + mid); for(int count =0;countRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.