Results 1 to 8 of 8
Thread: Need Help with JAVA String
- 05-24-2012, 08:50 AM #1
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
Need Help with JAVA String
Im trying to make it so that I can't to out put as the example! is only:
S: - - - - ; A: - A - A ; V: - - V -; J : J - - -
Help Please ME!
Thank you very much!
- - - -
S
- - - -
A
- A - A
V
- A V A
D
- A V A
J
J A V A
Bingo! You won.
This is my program:
import java.util.*;
class GuessWordJava {
public static void main ( String[] args ){
Scanner scanner = new Scanner(System.in);
//scanner.useDelimiter(System.getProperty("line.sepa rator"));
System.out.print("\n Enter secret entence : ");
String sentence = scanner.next();
int length = sentence.length();
while( true) {
char letter;
System.out.print("\n Enter your guess : ");
char ch = scanner.next().charAt(0);
if ( ch == ' ') {break;}
String str="";
for (int i = 0; i < length; i++){
letter = sentence.charAt(i);
if ( letter == ch ){
str=str+letter;
} else {
str= str+ "-";
}
}
System.out.print(str);
}
}
}
- 05-24-2012, 09:03 AM #2
Re: Need Help with JAVA String
In the poll thread I closed (and have now removed) I asked you to go through some links before starting a new thread. Clearly, you didn't bother.
Here they are again:
Forum Rules
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-24-2012, 09:09 AM #3
Re: Need Help with JAVA String
Consider using a char array to hold the guessed letters. Iterate over the secret word and for each guessed letter copy it into the array at the same position.
- 05-24-2012, 01:06 PM #4
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
Re: Need Help with JAVA String
Please send to me - code for solution ! Thank for your help!
- 05-24-2012, 01:14 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
Re: Need Help with JAVA String
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-24-2012, 05:46 PM #6
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
Re: Need Help with JAVA String
Jos - I'm beginner and I can't finish it for long time! so I'd like to complete code for my program!
- Your reply are not value! Every mad - fool men can say that!
Are you a teacher or educator or...... ??? plz see yourself in mirror!
Thien
- 05-24-2012, 06:02 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 12
- Rep Power
- 0
Re: Need Help with JAVA String
He was kidding you. I'm sure he would be happy to write the code for you at his current rate. Well, maybe not after you called him a fool. Do they have mirrors where you live?
- 05-25-2012, 08:22 AM #8
Member
- Join Date
- May 2012
- Posts
- 4
- Rep Power
- 0
Re: Need Help with JAVA String
I finish my program - This is my complete programe!
Java Code:import java.util.*; class GuessWordJava { public static void main ( String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("\n Enter sentence : "); String str = scanner.next(); StringBuffer str1 = new StringBuffer(); System.out.print("\n Enter char : "); char ch = scanner.next().charAt(0); char letter; for( int i = 0; i < str.length(); i++) { letter = str.charAt(i); if ( letter ==ch){ str1.append(ch); } else { str1.append('-'); } } System.out.println(str1); while(true) { System.out.print("\n Enter char : "); char ch1 = scanner.next().charAt(0); for( int j = 0; j < str.length(); j++) { letter = str.charAt(j); if ( letter == ch1){ str1.setCharAt(j,ch1); } } System.out.println(str1); } } }Last edited by JosAH; 05-25-2012 at 08:29 AM. Reason: added [code] ... [/code] tags
Similar Threads
-
Java Error cannot be applied to (java.lang.String), phone book entry program.
By iceyferrara in forum New To JavaReplies: 12Last Post: 09-23-2011, 01:25 PM -
Error Message - "Operator || cannot be applied to java.lang.String,java.lang.String"
By Crazz in forum NetBeansReplies: 3Last Post: 05-02-2011, 07:51 AM -
arrange(java.lang.String[][]) in Test cannot be applied to (java.lang.String) arrange
By prizzly in forum New To JavaReplies: 4Last Post: 01-01-2011, 10:52 AM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks