I have to create a program in java that reads a string from the user which contains dot (.) sign on it. I need to delete the dot and the char before it, and print the result.
So if the input is : mx.erw.ho.abe.a
It should print : merhaba
Or if the input is : lok.okl. u.ay.t t.tho.p.e e.sku.y
It should print : look at the sky
This is what i have done so far, which kind of works but it cuts out even the last letter of the word (if it is merhaba, this code prints merhab and if it is look at the sky, it prints look at the sk
How can i fix this?
public class HiddenMessage {
public static void main (String [] args) {
String [] message="lok.okl. u.ay.t t.tho.p.e e.sku.y".split("[.]");
for(int i=0;i<message.length;i++) {
System.out.print(message[i].substring(0, message[i].length()-1));
}
}
}
Update:
So now my code looks like this if i want to take the input from the user. It prints merhaba just fine but it only prints "look" not "look from the sky"
import java.util.Scanner;
public class HiddenMessage {
public static void main (String [] args) {
Scanner input=new Scanner (System.in);
System.out.println("Please enter the message: ");
String message=input.next();
String m1=message.replaceAll("\\w\\*", "");
System.out.print(m1);
}
}