Task - String Programs - Secret Message #33
Replies: 40 comments 1 reply
-
|
`public class SecretMessage { } |
Beta Was this translation helpful? Give feedback.
-
|
public class Stringfunctions { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
public class Main |
Beta Was this translation helpful? Give feedback.
-
|
public class SecretMessage { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`import java.util.*; public class SecretMessage { } |
Beta Was this translation helpful? Give feedback.
-
|
`package StringOperations; public class StringReplace { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`public class StringFunctions { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
public class MyClass { |
Beta Was this translation helpful? Give feedback.
-
|
`public class SecreatMessage { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
-
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;
}
} |
Beta Was this translation helpful? Give feedback.
-
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());
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
'''java public class Decipher { } |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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());
}
}
|
Beta Was this translation helpful? Give feedback.
-
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"));
}
} |
Beta Was this translation helpful? Give feedback.
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.
Beta Was this translation helpful? Give feedback.
All reactions