0% found this document useful (0 votes)
25 views

Challenging Questions To Do in Java: 1. Palindrome Example 2

This document outlines 4 programming challenges: 1. Write a program to check if a word is a palindrome. 2. Write a program to find all combinations of adding/subtracting digits that sum to zero. 3. Write a program to take in a square pattern and output the number of filled squares after each 90 degree rotation. 4. Write a program to encrypt a string by arranging letters in a square pattern and reading down columns, with punctuation and blanks filled in.

Uploaded by

tharund23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Challenging Questions To Do in Java: 1. Palindrome Example 2

This document outlines 4 programming challenges: 1. Write a program to check if a word is a palindrome. 2. Write a program to find all combinations of adding/subtracting digits that sum to zero. 3. Write a program to take in a square pattern and output the number of filled squares after each 90 degree rotation. 4. Write a program to encrypt a string by arranging letters in a square pattern and reading down columns, with punctuation and blanks filled in.

Uploaded by

tharund23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

10001

01100
01000
00000

Challenging Questions to do in Java


1. PALINDROME
Write a program that takes an English word and test whether or not this word is a
palindrome. (e.g. a word that reads the same both forwards and backwards such as
level).
2. ALL IS NOTHING

Example 2:
Input:
4
0000
0100
0010
0001

19
25

Output:

3
6
7
8

Consider the sequence of digits from 1 through N (N<=9) in increasing order:


1234 N
Insert either a + (for addition) or a - (for subtraction) between each of the digits so
that the resultant sum is zero. Print all possible combinations that sum to zero.

4. SQUARE ENCRYPT

Example: Enter a number: 7


1+2-3+4-5-6+7=0
1+2-3-4+5+6-7=0
1-2+3+4-5+6-7=0
1-2-3-4-5+6+7=0

Write a program that encrypts an input string. (For extra marks write a program that
decrypts a given string using the rules outlined above.)

A secret code encrypts a message by putting it in an array and reading down the
columns (blanks are replaced by asterisks and full stops are added to fill up the array).

Imagine a square pattern divided into smaller squares as shown below. As you can
see seven of the smaller squares are filled in. If this is rotated clockwise by 90 degrees
and placed on top of the original pattern then more squares are filled in.

LETS*G
O*TO*T
HE*SAN
DWICH*
SHOP*T
ODAY..

The total number of filled in squares is now 13. Continuing in this way you can again
rotate and add the original pattern to the combination giving 19 black squares and one
more rotation + addition gives 25 black squares.

Example:
Input:
Lets go to the sandwich shop today
Output: Lohdsoe*ewhdtt*ioasoscpy**ah*.gtn*t.

3. ROTATE THE SQUARE

You must write a program that will read in a square pattern and output the original
number of black squares and the number that result from each rotation.
Input:
- an integer N on a single line
- the next N lines consist of the NxN square,
(where 1 represents a black square and 0 represents a white square)
Output:
- four lines containing the number of black squares before each rotation
Example 1 :
Input:
5
10100

Output:

7
13

You might also like