2 Replies - 399 Views - Last Post: 29 March 2012 - 04:08 PM Rate Topic: -----

#1 Banana21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-March 12

Trouble with compiling

Posted 29 March 2012 - 04:03 PM

i got pretty far on this code but the complier says there is an error. If you can help me solve this problem that would be wonderful!

replace characters with similar-looking symbols: e becomes 3, i becomes 1, l becomes 7, and o becomes 0. Write a program to carry out these replacements with a sample string.
Complete the following code:
public class ReplacementTester
{
   public static void main(String[] args)
   {
      String greeting = "Hello, elite hacker!";
      greeting = greeting.replace("e" , "3");
      greeting = greeting.replace("i" , "1");  
      greeting = greeting.replace("l" , "7");
      greeting = greeting.replace("o", "0");
      
// call the replace method four times

      System.out.println(modifiedGreeting);
      System.out.println("Expected: H3770, 371t3 hack3r!");
   }
}



*Edited: code tags fixed. :code:

This post has been edited by pbl: 29 March 2012 - 09:52 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with compiling

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Trouble with compiling

Posted 29 March 2012 - 04:07 PM

What error does it give you?
Was This Post Helpful? 0
  • +
  • -

#3 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Trouble with compiling

Posted 29 March 2012 - 04:08 PM

Keep in mind, saying "there's a compile error" doesn't help us much.

Also: :code:

The error is because you've used a variable that doesn't exist. In the println call, you're referencing modifiedGreeting, but you use greeting to hold your string. Just use greeting instead.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1