Question: Software Construction - SE 4 1 1 Semester 2 0 2 Lab 5 - Best Practices Determine the bad practices of the following codes if

Software Construction - SE411
Semester 202
Lab 5- Best Practices
Determine the bad practices of the following codes if any.
package palindrome;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args){
Scanner i = new Scanner(
System.in);
System.out.print ln("Enter a number: ");
int n= i.nextInt ();
int r, orgInt =n;
for ( ;n0;n=n10)
r=n%10;
int revint = revint **10+r;
if (!(orgInt == revint))
System.out.println(orgInt +" is not a palindrome.");
if (orgInt == revint)
System.out.println(orgInt +" is a palindrome.");
}
}
Bad practices:
Rewrite The code:
1| Pag e
Software Construction - SE411
Semester 202
Lab 5- Best Practices
package palindrome;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args){
Scanner i = new Scanner(
System.in);
System.out.print ln("Enter a number: ");
int n= i.nextInt();
int r, orgInt =n;
for( ;n0;n=n10
r=n%10;
int revint = revint **10+r;
}
if (!(orgInt == revint)){
}
System.out.print ln(orgInt +" is not a palindrome.");
if (orgInt == revint){
System.out.print ln(orgInt +" is a palindrome.");
}
}
}
Bad practices:
Rewrite the code :
2| P ag e
Software Construction - SE411
Semester 202
Lab 5- Best Practices
package palindrome;
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args){
Scanner input = new Scanner(
System.in);
System.out.print ln("Enter a number: ");
int num = input.nextInt ();
int remainder, originalinteger = num;
for (; num !=0; num = num /10){
remainder = num %10;
int reversedinteger = reversedinteger **10+ remainder;
}
if (!(originalinteger == reversedInteger ){
System.out.println(originalinteger +" is not a palindrome.");
}
if (originalinteger == reversedinteger){
System.out.println(orignalinteger +" is a palindrome.");
}
}
}
Bad practices:
Rewrite Code :
3| Pag e
 Software Construction - SE411 Semester 202 Lab 5- Best Practices Determine

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!