For simple usage of GUIs, why would the source codes (shown below) not work? (a) The input/output objects have not been properly handled. (b) The data type of the methods has been defined in a wrong way. (c) The necessary parameters in the methods have not been assigned properly. (d) The flow of execution has been applied in a wrong way. import javax.swing.JOptionPane; public class Palindrome { public static void main(String[] args) //main method { long num1, num2; //variables to store the numbers String inputStr, outputStr; // strings to receive from the user // and display inputStr=JOptionPane.showInputDialog("Enter the number: "); num1 = Long.parseLong(inputStr); // change the string to num2 = num1; // numbers if (num1 <= 0) { num1 = - num1; //if the numbers are negative, change the sign inputStr = inputStr.valueOf(num1);//change the inputStr value } if (isPalindrome(inputStr)) outputStr = num2 + " is a palindrome"; else outputStr = num2 + " is not a palindrome"; JOptionPane.showMessageDialog(null, outputStr,"Palindrome Program",JOptionPane.INFORMATION_MESSAGE); System.exit(0); } public static void isPalindrome(String str) //call this method { int len = str.length(); int i, j; j = len - 1; for (i = 0; i <= (len - 1) / 2; i++) { if (str.charAt(i) != str.charAt(j)) return 0; j--; } return 1;
For simple usage of GUIs, why would the source codes (shown below) not work?
(a) The input/output objects have not been properly handled.
(b) The data type of the methods has been defined in a wrong way.
(c) The necessary parameters in the methods have not been assigned properly.
(d) The flow of execution has been applied in a wrong way.
import javax.swing.JOptionPane;
public class Palindrome
{
public static void main(String[] args) //main method
{
long num1, num2; //variables to store the numbers
String inputStr, outputStr; // strings to receive from the user
// and display
inputStr=JOptionPane.showInputDialog("Enter the number: ");
num1 = Long.parseLong(inputStr); // change the string to
num2 = num1; // numbers
if (num1 <= 0)
{
num1 = - num1; //if the numbers are negative, change the sign
if (isPalindrome(inputStr))
outputStr = num2 + " is a palindrome";
else
outputStr = num2 + " is not a palindrome";
JOptionPane.showMessageDialog(null, outputStr,"Palindrome
Program",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
public static void isPalindrome(String str) //call this method
{
int len = str.length();
int i, j;
j = len - 1;
for (i = 0; i <= (len - 1) / 2; i++)
{
if (str.charAt(i) != str.charAt(j))
return 0;
j--;
}
return 1;

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









