AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-string-handling: Hidden message

A group of friends share messages in a WhatsApp group. Since there is a risk of their ideas being hacked, they form a new method of sharing text messages which is confusing for the person who hacks/views those messages. Now your task is to create a program for the hacker to solve his issue in decoding the messages.
Sample input:
REAEALAL L S STSTETEEEEL
Output:
REAL STEEL

corejava x 353
string-handling x 34
Posted On : 2016-12-29 20:15:47.0
profile Raksha - anyforum.in Raksha
2510
up-rate
5
down-rate

Answers


import java.util.Scanner;

public class HiddenMessage {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String s1 = input.nextLine();
String output = decode(s1, 3);
System.out.println(output);
}

static String decode(String input, int length) {
String output = "";
for(int i = 0;i<input.length();i+=length) {
output +=input.charAt(i);
if(i+length>=input.length())
/*When it reaches to the end, the repeating has to be stopped.*/
output += input.substring(i+1);
}
return output;
}
}

Posted On : 2016-12-31 00:40:33
Satisfied : 3 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222694
Reply This Thread
up-rate
5
down-rate
Comments
It works!!
profile Raksha - anyforum.in Raksha
25  1  0
Posted On :2016-12-31 08:32:20.0
Leave a Comment
You're Welcome..
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1882  22694
Posted On :2017-01-07 00:17:07.0
Leave a Comment
Not all characters in a 'String' will fit into one...
profile Lew Bloch - anyforum.in Lew Bloch
0  0  0
Posted On :2017-01-25 01:08:50.0
Leave a Comment



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in