Results 1 to 20 of 24
- 03-21-2012, 07:22 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
- 03-21-2012, 07:23 PM #2
Re: Convert some characters of a string to uppercase
What have you tried? Where are you stuck?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-21-2012, 07:30 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
i tried to do something like this:
for(int i=0;i<s.length();i++){
if(check) {
s.toUpperCase();
}
if(s.charAt(i)== ' '){
check=true;
}
else
check=false;
}
System.out.println(s.toUpperCase());
}
But this converts the whole string to uppercase. i thought that only if the character is :' ' ,it will convert the character to uppercase.
- 03-21-2012, 07:46 PM #4
Re: Convert some characters of a string to uppercase
The toUpperCase method converts the contents of the whole String object. If you only want to change one char in the String, you will need to find a way to get to that one char.
If you don't understand my response, don't ignore it, ask a question.
- 03-21-2012, 08:11 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
i want to transform the first letter of each word belonging to a string into a capital letter.
- 03-21-2012, 08:23 PM #6
Re: Convert some characters of a string to uppercase
A couple of ways to do it:
Break the String up into parts, change the letter and then put the String back together.
Put the String into a StringBuffer or StringBuilder, scan the buffer and change the letters and then create a new String from the StringBuffer.If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 03:58 PM #7
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
could you please write how to do it because i have some problem?
- 03-22-2012, 04:12 PM #8
Re: Convert some characters of a string to uppercase
I think the reason for your assignment is for you to learn how to program. You won't learn if I do the work.
Describe how you are trying to solve the problem and Post your code with the problems you are having.If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 04:21 PM #9
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
i tried this:
Java Code:import java.util.Scanner; import java.lang.String; import java.lang.Character; public class exercise4 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); boolean check=true; char[] array = new char[s.length()]; for(int i=0;i<s.length();i++){ if(Character.isLetter(s.charAt(i))){ System.out.print(s.charAt(i)); }else{ System.out.println(""); array[i]=s.charAt(i); array = s.toCharArray(); } if(check) { s.toUpperCase(); } if(s.charAt(i)== ' '){ check=true; } else check=false; } System.out.println(s.toUpperCase()); } }Last edited by Norm; 03-22-2012 at 04:56 PM. Reason: added code tags
- 03-22-2012, 04:35 PM #10
Re: Convert some characters of a string to uppercase
You did not answer my questioh: Describe how you are trying to solve the problem.
How does your code get the characters one at a time?
How does it determine if a character should be converted to uppercase?
How does it test if that character is upper or lower case
how does it change that character to uppercase?
How does it create the result String using the characters it looked at one by one?If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 04:47 PM #11
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
i also tried to do this:if the character is ' ' , i should call the toUpperCase method and make this character uppercase. but this doesnot work
- 03-22-2012, 04:49 PM #12
Re: Convert some characters of a string to uppercase
Post the code where you try to change the case of one character.
Given this:
char aChar = 'a';
show how you would change the value of aChar to 'A'.
You still have not answered this:
Describe how you are trying to solve the problem.Last edited by Norm; 03-22-2012 at 04:57 PM.
If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 05:04 PM #13
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
import java.lang.Character;
char aChar = 'a';
System.out.println(Character.toUpperCase(aChar));
- 03-22-2012, 05:06 PM #14
Re: Convert some characters of a string to uppercase
Now put it all together.
Describe/list the steps the program must do to solve this problem.If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 05:16 PM #15
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
import java.lang.String;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String s = in.nextLine();
for(int i=0;i<s.length();i++){
s.toUpperCase();
}
System.out.println(s.toUpperCase());
}
}
- 03-22-2012, 05:19 PM #16
Re: Convert some characters of a string to uppercase
Don't write any code until you know what the code is supposed to do.
Before you write any more code, respond to this:
Describe/list the steps the program must do to solve this problem.
See post#10 for some ideasIf you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 05:25 PM #17
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
This code that i wrote reads a string from the keyboard, then it converts the characters of the string to uppercase and finally it prints the string with the uppercase characters
- 03-22-2012, 05:26 PM #18
Re: Convert some characters of a string to uppercase
Is the problem solved then? Does the program do what you want it to do?
If you don't understand my response, don't ignore it, ask a question.
- 03-22-2012, 05:33 PM #19
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Re: Convert some characters of a string to uppercase
no, if the problem was solved, i wouldn't be there.
i want the first character of each word to be uppercase not all the characters of the string.
- 03-22-2012, 05:35 PM #20
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Need help with convert to uppercase program!
By ultimashadow in forum New To JavaReplies: 3Last Post: 01-31-2012, 09:49 AM -
convert characters to its equivalent value in decimal and hexadecimal
By ivylim88 in forum New To JavaReplies: 1Last Post: 09-17-2010, 12:40 PM -
Automatic convert to uppercase in keyevents
By ashin in forum SWT / JFaceReplies: 4Last Post: 08-09-2010, 01:59 PM -
Convert integers into ACSII characters.
By Valkyrie in forum New To JavaReplies: 4Last Post: 11-24-2009, 02:39 AM -
String uppercase/lowercase
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:22 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks