Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

People who exercise more tend to weigh less.

Answered: 1 week ago