|
|||||||
| Off-Topic Anything and everything off topic. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
I've got a Java assignment due on Sunday night, problem is, i'm going out of town Friday afternoon for the weekend and will not be around a PC.
I'm stumped and need some help. Let me know if you can help me out.
__________________
1979 Yamaha XS650 - new project 1985 Yamaha XJ700 1982 Yamaha XJ650 - SOLD!! 2003 Kawasaki ZX6- R - SOLD!! 1989 Yamaha TW200 (SOLD) |
|
#2
|
||||
|
||||
|
my java is limited to rotating banners at the top of a forum~
__________________
''The man hunched over his motorcycle can focus only on the present instant of his flight; he is caught in a fragment of time cut off from both the past and the future; he is wrenched from the continuity of time ... in other words, he is in a state of ecstasy; in that state he is unaware of his age, his wife, his children, his worries, and so he has no fear, because the source of fear is in the future, and a person freed of the future has nothing to fear.'' www.myspace.com/midmoriders |
|
#3
|
|||
|
|||
|
i know bits and pieces, depends on what you're trying to do. did this little 'into to javascript' during my html classes junior and senior year and took C++ programming my freshman year of college, but those have been a couple years at least.
__________________
~"Have you ever noticed that 'lol' looks like a drowning guy? I bet he's not laughing out loud." ~"Blaming a shooting on a gun is like me blaming my spelling errors on my keyboard." ~YouTube- Over Powered Powerwheels Snow Jam Barbie Jeep vs. Corvette vs. F150 vs. Mustang Crazy Drift |
|
#4
|
||||
|
||||
|
I think javascript may be slightly different than java - but I'm new to it so I may be wrong. Anyway.
I'm trying to get it to capitalize the first word of a sentence. I can get it to capitalize every word (see code below), but I just want the FIRST word of a sentence. When the user enters: hello, how are you today? i'm doing great! I want it to display: Hello, how are you today? I'm doing great! Here's what I've got so far. I'll add the Scanner class later to accept a users input. Right now I just have a string initialized for testing purposes. I have been working on and thinking about this for two days. I've tried so many variations that I'm going cross eyed. At one point, I had it working except it didn't space between the ending punctuation mark and the next word, but couldn't figure out how to add the space in - but now I don't remember what all I changed. Code:
public class CapitalizeFirst {
public static void main(String[] args) {
String test = "hello, how are you today? ";
System.out.print("Original: " + test);
System.out.print("\nNew: " + title(test));
}
public static String title(String string){
for(int i = 0; i < string.length(); i++){
if(i == 0){
string = String.format("%s%s", Character.toUpperCase(string.charAt(0)), string.substring(1));}
if(!Character.isLetterOrDigit(string.charAt(i))){
if(i + 1 < string.length()){
string = String.format("%s%s%s", string.subSequence(0, i + 1),
Character.toUpperCase(string.charAt(i + 1)), string.substring(i + 2));
}
}
}
return string;
}
}
__________________
1979 Yamaha XS650 - new project 1985 Yamaha XJ700 1982 Yamaha XJ650 - SOLD!! 2003 Kawasaki ZX6- R - SOLD!! 1989 Yamaha TW200 (SOLD) |
|
#5
|
|||
|
|||
|
I'm guessing you're trying to code a program that checks/corrects spelling/grammer errors? Not sure if there's a specific code for it, but I would think you could use and if then function.
If First=lowercase Then CapitalizeFirst You would prolly have to enter a string somewhere that would cause it to recognize the first letter and I don't know if it would recognize lowercase or capitalize as objects/commands. if it didn't then it'd be a looong bit of typing... if First=a then substitute A I still have my C++ programming book from College, I'll have to take a look at it sometime tomorrow. If anything useful does pop up, you're welcome to borrow it. Heck I've still got the program given to us to use for the class.
__________________
~"Have you ever noticed that 'lol' looks like a drowning guy? I bet he's not laughing out loud." ~"Blaming a shooting on a gun is like me blaming my spelling errors on my keyboard." ~YouTube- Over Powered Powerwheels Snow Jam Barbie Jeep vs. Corvette vs. F150 vs. Mustang Crazy Drift Last edited by RebelKittyn; 09-02-2010 at 10:58 AM. |
|
#6
|
||||
|
||||
|
Thanks, but I was up until 4am, but figured it out.
__________________
1979 Yamaha XS650 - new project 1985 Yamaha XJ700 1982 Yamaha XJ650 - SOLD!! 2003 Kawasaki ZX6- R - SOLD!! 1989 Yamaha TW200 (SOLD) |
![]() |
| Thread Tools | |
| Display Modes | |
|
|