Results 1 to 3 of 3
Thread: basic help needed
- 03-02-2009, 06:29 PM #1
Member
- Join Date
- Mar 2009
- Location
- England, London
- Posts
- 1
- Rep Power
- 0
basic help needed
Hey all, this is my first post, i've been using Java for about 5 months now and I'm still pretty new to programming let alone the language.
I need some help with some code:
import java.util.Scanner;
public class HangMan
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
String strDash = "__________";
String strWord = "helloworld";
while(true)
{
System.out.println(strDash);
System.out.println("Pick a letter");
String s = sc.next();
char c = s.charAt(0);
for(int i = 0;i < strWord.length() - 1; i++)
{
if(strWord.charAt(i) == c)
{
strDash.charAt(i) = c;
}
}
}
}
}
I'm trying to change the letters in strDash if they match with the users input compared to strWord and getting:
HangMan.java:30: unexpected type
required: variable
found : value
strDash.charAt(i) = c;
^
1 error
No idea what's wrong with that line and i think it must be a simple answer but just can't figure it out, thanks in advance for any help you can provide :)Last edited by CurtisJC; 03-02-2009 at 06:31 PM.
- 03-02-2009, 06:48 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because a String is immutable (it can't be changed). Look at the API docs String, the method replace, and assign the result to a new String.
- 03-02-2009, 07:21 PM #3
To String or not to String ...
Here's the link to the Java 6 APIs:
Java Platform SE 6
Here's the link to the particular String replace() method:
String Replace ()
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
Basic Java help, AIM?
By jkswebsite in forum New To JavaReplies: 4Last Post: 07-11-2012, 06:17 PM -
Basic Help
By robjames in forum New To JavaReplies: 3Last Post: 02-09-2009, 02:58 AM -
Need some really basic help
By Mayur in forum New To JavaReplies: 6Last Post: 01-24-2009, 06:00 AM -
Very basic question
By gvi in forum New To JavaReplies: 2Last Post: 10-30-2007, 06:30 PM -
help with basic example
By fred in forum New To JavaReplies: 1Last Post: 07-20-2007, 05:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks