Problem: Palindrome
Draw a palindrome of a given number.
Sample Input:
5
Sample Output:
1 2 3 4 5 4 3 2 1
Solve:
Lets see the following Code:
Console:
Enter any Int Num:5
1 2 3 4 5 4 3 2 1
Happy Coding :)
-@D
Draw a palindrome of a given number.
Sample Input:
5
Sample Output:
1 2 3 4 5 4 3 2 1
Solve:
Lets see the following Code:
// ADLabs
import java.util.Scanner;
public class NastedForLoop {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter any Int Num:");
int n = sc.nextInt();
System.out.println();
// Palindrome
for (int i = 1; i <= n; i++) {
System.out.print(i + " ");
}
for (int i = n - 1; i > 0; i--)
System.out.print(i + " ");
System.out.println();
sc.close();
}
}
Console:
Enter any Int Num:5
1 2 3 4 5 4 3 2 1
Happy Coding :)
-@D