Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please Help I'm stuck

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Please Help I'm stuck

    Hello ,
    I am having trouble with my code I am a beginner and I know I probably made a mistake somewhere but can't figure out where .
    -I want to only have 7 letters to output but I can't figure out what is wrong , Every time i type less than 7 letters I get an error
    - I want to have an hyphen between the 3 and fourth number but don;t know how to make it work .
    -How can I replace a space between an input words by nothing every time I have a space between a word It give me a zero
    Please I am stuck if someone can help me.

    Thank you so much
    static  String[] Number1 =   new String [7];
    	static String Number;
     
        public static void main (String[] args) {
     
     Scanner console = new Scanner(System.in);
    System.out.print ("Enter a word:");                
     
          Number = console.nextLine();
          for (int i = 0; i < Number1.length; i++) {
     
        System.out.print(Letter(Number.toUpperCase().toLowerCase().charAt(i)));
          }
        }
     
    public static int Letter (char UppercaseLowerCase)     {
    	 int print=1 ;
     
         if (UppercaseLowerCase=='A' || UppercaseLowerCase=='B' || UppercaseLowerCase== 'C' ||
      	   UppercaseLowerCase=='a' || UppercaseLowerCase=='b' || UppercaseLowerCase== 'c' )   {
               print= 2;
           }
          else if(UppercaseLowerCase=='D' || UppercaseLowerCase=='E' || UppercaseLowerCase== 'F' ||
           	   UppercaseLowerCase=='d' || UppercaseLowerCase=='e' || UppercaseLowerCase== 'f' ) {
               print = 3;
           }
          else if (UppercaseLowerCase=='G' || UppercaseLowerCase=='H' || UppercaseLowerCase== 'I' ||
            	   UppercaseLowerCase=='g' || UppercaseLowerCase=='h' || UppercaseLowerCase== 'i' ) {
               print = 4;
           }
          else if (UppercaseLowerCase=='J' || UppercaseLowerCase=='K' || UppercaseLowerCase== 'L' ||
            	   UppercaseLowerCase=='j' || UppercaseLowerCase=='k' || UppercaseLowerCase== 'l' ) {
               print = 5;
           }
          else if (UppercaseLowerCase=='M' || UppercaseLowerCase=='N' || UppercaseLowerCase== 'O' ||
            	   UppercaseLowerCase=='m' || UppercaseLowerCase=='n' || UppercaseLowerCase== 'o' ){
               print = 6;
           }
          else if (UppercaseLowerCase=='Q' || UppercaseLowerCase=='R' || UppercaseLowerCase== 'S'
        		  ||UppercaseLowerCase== 'P'||
            	   UppercaseLowerCase=='q' || UppercaseLowerCase=='r' || UppercaseLowerCase== 's' 
            	   ||UppercaseLowerCase== 'p')          {
               print = 7;
           }
          else if (UppercaseLowerCase=='T' || UppercaseLowerCase=='U' || UppercaseLowerCase== 'V' ||
            	   UppercaseLowerCase=='t' || UppercaseLowerCase=='u' || UppercaseLowerCase== 'v' ){
               print = 8;
           }
          else if (UppercaseLowerCase=='W' || UppercaseLowerCase=='X' || UppercaseLowerCase== 'Y' 
        		  ||UppercaseLowerCase== 'Z' ||
            	   UppercaseLowerCase=='w' || UppercaseLowerCase=='x' || UppercaseLowerCase== 'y' 
            	   ||UppercaseLowerCase== 'z' ){
               print = 9;
           }
         return print ;
        }
     
    }


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Please Help I'm stuck

    In your code, replace Number1.length with Number.length() in the for loop. Then it works.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Please Help I'm stuck

    With String[] Number1 = new String [7], you are making collection of 7 strings. Is this what you want? It is easier to make one string with 7 characters.

  4. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please Help I'm stuck

    ILan can you please tell me how I can do that

Similar Threads

  1. Help! im stuck!
    By aznguy92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2011, 09:16 PM
  2. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  3. PLEASE PLEASE I AM STUCK...
    By ThejavaBUM in forum Loops & Control Statements
    Replies: 2
    Last Post: April 5th, 2011, 10:16 PM
  4. Stuck again
    By Tate in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 28th, 2010, 11:22 AM
  5. Stuck help please!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2010, 05:31 PM