Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By gimbal2

Thread: P-language

  1. #1
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    148
    Rep Power
    0

    Default P-language

    I found an exercise in a book, that I just can't solve. "In the so called p-language all vowels are duplicated and a p is placed between the two duplicated vowels. Consonants and other characters are not changed. Write a program that reads a text that contains a message written in p-language, and then translates it to English." Can you help me with this? Because I just don't know how to do it :( I tried doing it with character arrays, and then moving the elements around, but as soon as I try to print the array out I just get some strange signs and numbers.

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,663
    Rep Power
    5

    Default Re: P-language

    No code = no help.
    jim829 likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    148
    Rep Power
    0

    Default Re: P-language

    Java Code:
    public class Tjena{
        public static void main(String[] args){
            
        }
    }

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,377
    Rep Power
    5

    Default Re: P-language

    You've got to be kidding me!!!!

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: P-language

    try to print the array out I just get some strange signs and numbers.
    Try this:
    Java Code:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: P-language

    Quote Originally Posted by jim829 View Post
    You've got to be kidding me!!!!
    At least it is better than those who whine "I don't know where to start".

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,663
    Rep Power
    5

    Default Re: P-language

    Quote Originally Posted by Junky View Post
    At least it is better than those who whine "I don't know where to start".
    I don't agree, this is a far bigger insult; to the OP and to the people he's asking for "help".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    148
    Rep Power
    0

    Default Re: P-language

    I apologize for being so rude and disrespectful earlier. Here is the actual code that's not working :(

    Java Code:
    import java.util.*;
    import javax.swing.*;
    
    public class Bajs{
    	public static void main(String[] args){
    		String s = JOptionPane.showInputDialog("Enter a sentence or a word"), t = s.toUpperCase();
    		int removedElements = 0;
    		char text[] = t.toCharArray();
    		for(int x=0;x<text.length-2;x++){
    			if(ärVokal(text[x]) && text[x+1] == 'P' && text[x] == text[x+2]){
    				text = removingElements(text, x);
    			}
    		}
    		JOptionPane.showMessageDialog(null, text);
    	}
    	
    	static boolean ärVokal(char c){
    		char vokaler[] = {'A', 'E', 'I', 'O', 'U', 'Y', 'Å', 'Ä', 'Ö'};
    		for(int x=0;x<vokaler.length;x++)
    			if(vokaler[x] == c)
    				return true;
     		return false;
    	}
    	
    	static char[] removingElements(char[] text, int index){
    		char newarray[] = text;
    		for(int x=index;x<index+3;x++){
    			for(int y=x;y<newarray.length;y++){
    				newarray[x] = newarray[x+1];
    			}
    		}
    		return newarray;
    	}
    }

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: P-language

    that's not working
    Did you try using the Arrays class's method that I posted?
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    148
    Rep Power
    0

    Default Re: P-language

    Quote Originally Posted by Norm View Post
    Did you try using the Arrays class's method that I posted?
    Yes.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: P-language

    Do you have a problem speaking english? Perhaps if you used Google translate you could create a better answer.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    148
    Rep Power
    0

    Default Re: P-language

    I apologize for not being among the 360 million people on this planet who have English as their native language, but I try to speak it as best as I can.

    I tried to do what you said and I did not get any strange signs or numbers anymore, however the characters were output like this for example: [A, M, S, P, P, S], and they did not form the words they were supposed to.
    Last edited by Zelaine; 10-02-2013 at 06:54 PM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: P-language

    they did not form the words they were supposed to.
    If you want to convert an array of char to a String, look at the String class. It has constructors and methods that will do that.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Java is an OOP language.
    By mysourha in forum New To Java
    Replies: 3
    Last Post: 01-14-2010, 10:15 AM
  2. Replies: 5
    Last Post: 08-25-2009, 09:41 AM
  3. Is this the right language?
    By rws in forum New To Java
    Replies: 9
    Last Post: 11-15-2008, 03:27 PM
  4. IDE for new language
    By mitra2008 in forum Eclipse
    Replies: 2
    Last Post: 06-23-2008, 06:43 PM
  5. V language 0.004
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-19-2007, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •