Skip to content

Added Palindromic Numbers in Every Language Article #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion _data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,9 @@ fuboki10:
bio: |
A Computer Engineering student at Faculty of Engineering Cairo University EG (2022).
Competitive Programmer 🔥.


anohene1:
name: Isaac Anohene
email: [email protected]
web: isaacanohene.me
bio:
75 changes: 75 additions & 0 deletions projects/palindromic-numbers/_posts/2020-10-07-kotlin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: Palindromic Numbers in Kotlin
layout: default
last-modified: 2020-10-07
featured-image:
tags: [palindrome]
authors:
- anohene1
---
In this article, we'll write a program that checks if a number is a palindrome or not in Kotlin.

## How to Implement the Solution

code for palindrome.kt:
```kotlin
fun main() {
var n: Int
var num: Int
var digit: Int
var rev: Int = 0

print("Enter a positive number: ")
num = readLine()!!.toInt()

n = num

do {
digit = num % 10
rev = (rev * 10) + digit
num = num / 10
}while (num != 0)

if (n == rev){
println(true)
}else{
println(false)
}
}

```

## How to Run Solution

To run the solution to check if a number is a palindrome or not, we first create some variables we will use in the algorithm in the main function as shown here:
```kotlin
var n: Int
var num: Int
var digit: Int
var rev: Int = 0
```
Then we will prompt the user to input the number that needs to be checked:
```kotlin
print("Enter a positive number: ")
num = readLine()!!.toInt()
```
Then we use a do while loop to reverse the number that was typed in:
```kotlin
do {
digit = num % 10
rev = (rev * 10) + digit
num = num / 10
}while (num != 0)
```
Finally, we check if the number and its reverse are the same or not. If they are the same, we tell the user that it's true, otherwise we tell the user that it's false, as shown here:
```kotlin
if (n == rev){
println(true)
}else{
println(false)
}
```

## Further Reading

- Fill out as needed.
42 changes: 42 additions & 0 deletions projects/palindromic-numbers/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Palindromic Numbers in Every Language
layout: default
date: 2020-10-07
last-modified: 2020-10-07
featured-image:
tags: [palindrome]
authors:
- anohene1
---

This is an article on how to check if a number is a palindrome in every language.

## Description

A palindrome number is a number that reads the same backward and forward.
Example: 343, 121, 909, 222

## Requirements

Create a file called "Palindrome Number" using the naming convention appropriate for your language of choice.
Write a program that accepts an input of an integer and prints whether the number is a palindrome or not.

## Testing
The following table contains various test cases that you can use to verify the correctness of your solution:

| Description | Input | Output |
|------------------------------|-------|--------|
| no input | None | Usage: please input a number |
| empty input | "" | Usage: please input a number |
| invalid input: not a number | a | Usage: please input a number |
| sample input: palindrome | 232 | true |
| sample input: not palindrome | 521 | false |


## Articles

{% include article_list.md collection=site.categories.palindromic-numbers %}

## Further Reading

- Fill out as needed