Task - String Programs - Secret Message #33
Replies: 40 comments 1 reply
|
`public class SecretMessage { } |
|
public class Stringfunctions { } |
|
|
|
|
|
|
|
public class Main |
|
public class SecretMessage { } |
|
|
`import java.util.*; public class SecretMessage { } |
|
`package StringOperations; public class StringReplace { } |
|
|
|
`public class StringFunctions { } |
|
|
public class MyClass { |
|
`public class SecreatMessage { } |
|
public class Secret {
public static void main(String[] args) {
String secretMsg = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9zssions";
secretMsg= secretMsg.replace('z', 'e');
secretMsg = secretMsg.replaceAll("[0-9]", " ");
secretMsg = secretMsg.replaceFirst("java", "obvious");
secretMsg= secretMsg.toUpperCase();
System.out.println(secretMsg);
}
} |
class Decode {
public static void main(String[] args) {
String secretMessage = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
System.out.println(secretMessage);
String decodedMessage = secretMessage.replaceAll("z", "e").replaceAll("\\d", " ")
.replaceFirst("java", "obvious").toUpperCase();
System.out.println(decodedMessage);
}
} |
package com.manvendra.message;
public class BreakingTheCode {
public static void main(String[] args) {
String secretMessage = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
System.out.println("Secret Message : "+ secretMessage);
String message = secretMessage.replace('z', 'e').replaceAll("[0-9]+", " ").replaceFirst("java", "obvious");
System.out.println("\nActual message after decoding : "+message);
}
} |
package com.src;
public class StringReplace {
public static void main(String[] args) {
String secretMessage = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
String message = decodeMessage(secretMessage);
System.out.println("The Secret Message is:"+message.toUpperCase());
}
private static String decodeMessage(String secretMessage) {
String regex = "\\d+";
String decodedMessage = secretMessage.replace('z', 'e').replaceAll(regex, " ").replaceFirst("java", "obvious");
System.out.println("decodedMessage:"+decodedMessage);
return decodedMessage;
}
} |
MessageDecode.javapackage main;
import java.util.Scanner;
public class MessageDecode {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Please Enter the Secret Message:");
Scanner sc = new Scanner(System.in);
String secretMessage = sc.nextLine();
secretMessage = secretMessage.replace('z', 'e');
secretMessage = secretMessage.replaceAll("[0-9]", " ");
secretMessage = secretMessage.replaceFirst("java","obvious");
System.out.println("The Decoded Message is as shown below:");
System.out.println(secretMessage.toUpperCase());
}
} |
|
|
'''java public class Decipher { } |
package mypackage;
public class SecretMessage {
public static void main(String[] args) {
// TODO Auto-generated method stub
String crackit = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
System.out.println(crackit);
String decodedMessage = (crackit.replace('z', 'e').replaceAll("[0-9]"," ").replaceFirst("java","obvious")).toUpperCase();
System.out.println(decodedMessage);
}
}
```java |
package com.string.excercise;
public class MainApp {
public static void main(String[] args) {
String secretMessage = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
String decodedMessage = secretMessage.replace('z', 'e').replaceAll("[0-9]", " ").replaceFirst("java", "obvious");
System.out.println(decodedMessage.toUpperCase());
}
}
|
package src.string.secret.program;
public class StringSecret {
public static void main(String[] args) {
// TODO Auto-generated method stub
String secretMessage = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
System.out.println(secretMessage);
System.out.println("Replace all occurrences of the letter 'z' with the letter 'e'");
secretMessage = secretMessage.replace('z', 'e');
System.out.println("Replace all the digits with a space");
secretMessage = secretMessage.replaceAll("[0-9]", " ");
System.out.println("Replace the first occurrence of \"java\" with \"obvious\".");
secretMessage = secretMessage.replaceFirst("java", "obvious");
System.out.println(secretMessage);
//by using lambda expression
String str1 = "Bzwarz!1It9is3java2whzn1you5arz4using3phonzs8during1thz9szssions";
System.out.println((str1.replace("z", "e")).replaceAll("[0-9]", " ").replaceFirst("java", "obvious"));
}
} |
Uh oh!
There was an error while loading. Please reload this page.
Breaking the Code
It's rudimentary, Watson!
In this program, we will be discussing various methods for replacing multiple characters in String. This can be done using the methods listed below:
Syntax:
public String replace(char oldch, char newch)Syntax:
public String replaceAll(String regex, String replace_str)Syntax:
public String replaceFirst(String regex, String replace_str)The following string contains a secret message:
In order to decipher the secret message, do the following in order:
WAP to decipher the coded message and print the decoded message in ALL CAPS.
All reactions