Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners String conversion

Have Programming Question? Ask it here!
 
 
 


Akhilesh Chafale
String conversion
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


I want to convert a string of mix cases(lower and upper case) to vice versa.

ex.

HellO should be printed to hELLo.

the string comes from user using datainputstream. Also sending individual chars of string to toUpperCase() and toLowerCase() not possible.


Advertisement
View Answers

March 7, 2011 at 5:21 PM


Java String Case Converter

import java.util.*;

class StringExample {
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                System.out.print("Enter string: ");
                String str = input.nextLine();
                StringBuffer sb = new StringBuffer();
                char ch[] = str.toCharArray();
                for (int i = 0; i < ch.length; i++) {
                        if (ch[i] == ' ') {
                                sb.append(" ");
                        }
                        if (Character.isLowerCase(ch[i])) {
                                char cha = Character.toUpperCase(ch[i]);
                                sb.append(Character.toString(cha));
                        } else if (Character.isUpperCase(ch[i])) {
                                char cha = Character.toLowerCase(ch[i]);
                                sb.append(Character.toString(cha));
                        }
                }
                System.out.println(sb.toString() + " ");
        }
}


Related Tutorials/Questions & Answers:
String conversion
String conversion  I want to convert a string of mix cases(lower and upper case) to vice versa. ex. HellO should be printed to hELLo. the string comes from user using datainputstream. Also sending individual chars of string
javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript">..., this works result = a + b + c; printWithType(result); //123 string
Advertisements
Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0...'; chr++) { (int) String "count"+chr = 0
HSSFCell to String type conversion
HSSFCell to String type conversion  Hello, Can anyone help me convert HSSFCell type to string. There is a solution in the following URL, but the method getWorkbook() is not defined for the class HSSFCell. Thanks in advance
String to Date Conversion - Java Beginners
String to Date Conversion  Hi , I am retreiving time stamp of a file and then inserting it into ACCESS DB. I am converting it to string format.... Hence I need some help for converting my String Date format to Date format, so
java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have... into seperation.fo that i want to convert into string, after that split the string... : import java.util.*; class ArrayListToString { public static void main(String
PHP Array to String Conversion
PHP Array to String Conversion Sometimes data arrive in array which has... is used to convert the array into string. In PHP, conversion of an array to string... Array to String Conversion Example 1: <?php $array1=$array2=array
Conversion from string data type into different data types.
Conversion from string data type into different data types.  string str="World id Beutifull"; char chr[20]; char* chrctr ; Qustion is -How to store the 'str' value in 'chr' and 'chrctr'? int abc; sprintf(abc ,"%s",str
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+subResult=0+subCause=0
conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+ prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+ subResult=0+subCause=0
Conversion from short to String
Conversion from short to String: In this tutorial we will learn how to convert... a short type value from console and provides a conversion to String type. The line... Conversion from short type to String type---"); System.out.println("Enter short
String to Int Conversion
String to Int Conversion       This section illustrates you how to convert a string into its integer equivalent. To demonstrate the conversion of string into an integer we are taking
Conversion from byte to String
Conversion from byte to String: In this tutorial we will learn how to convert a byte type value to String type value. Description: This program will take a byte value from console and provides a conversion to String type data
Conversion from float to String
Conversion from float to String: In this tutorial we will learn how to convert... will take a float value from console and provides a conversion to String type data... Conversion from float type to String type---"); System.out.println("Enter float
Conversion from double to String
Conversion from double to String: In this tutorial we will learn how... will take a double value from console and provide the conversion to String type...("---Data Conversion from double type to string type---"); System.out.println
Conversion from long to string
Conversion from long to String: In this tutorial we will learn how to convert a long type value to String type value. Description: This program will take a long type value from console and provide the conversion to String type
Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert a String from one case into another case. Upper to Lower case Conversion... into lower case char/String. Lower to Upper case Conversion : By using toUpperCase
Conversion from int to String
Conversion from int to String: In this tutorial we will learn how to convert an int type value to a String type. You will convert an int value  to String by using toString() method. Description: This program will take an int
Conversion from String to int
Conversion from String to int: In this tutorial we will learn how to convert a string type data to int type data. Description: This program will take a String value from mystring variable. The line int myint = Integer.parseInt
Conversion from String to byte
Conversion from String to byte: In this tutorial we will learn how to convert a string type data to byte type data. Description: This program will take a String value from mystring variable. The line byte mybyte = Byte.parseByte
Conversion from String to short
Conversion from String to short: In this tutorial we will learn how to convert a string type data to short type data. Description: This program will take a String value from mystring variable. The line short myshort
Conversion from String to long
Conversion from String to long: In this tutorial we will learn how to convert a string type data to long type data. Description: This program will take a String value from mystring variable. The line long mylong = Long.parseLong
Conversion from String to float
Conversion from String to float: In this tutorial we will learn how to convert a string type data to float type data. Description: This program will take a String value from mystring variable. The line float myfloat
Conversion from String to double
Conversion from String to double: In this tutorial we will learn how to convert a string type data to double type data. Description: This program will take a String value from mystring variable. The line double mydouble
Conversion from String to boolean
Conversion from String to boolean: In this tutorial we will learn how to convert a string type data to boolean type data. Description: This program will take a String value from mystring variable. The line boolean mybool
Conversion from String to char
Conversion from String to char: In this tutorial we will learn how to convert a string type data to char type data. Description: This program will take a String value from mystring variable. The line Character mychar
conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles in a JTextField and then converts mile to kilometers and display the result as XX.XX
currency conversion
currency conversion   hi frds.. I wan jsp code to convert currency in different formats??... if u know plz plz plz post it   Please visit the following link: http://www.roseindia.net/tutorials/I18N/currency
Java date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many... string. For example, d -  denotes the day in month M- denotes the month
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
java conversion
java conversion  how do i convert String date="Aug 31, 2012 19:23:17.907339000 IST" to long value
image conversion tools
image conversion tools  how many tools are available in image conversion at particularlly in java
Type Conversion - Java Beginners
from integer value to a string value .In a database operation i want to convert it.   hi jagadish Suppose int num = 10; String id = ""+num... for conversion
Convert Double To String
; This section learns you the conversion of double into string. The following program... Convert Double To String      ... a variable of double type and convert it into the string form by using toString
.wav file conversion
.wav file conversion   how to read .wav file and converd the data into text format
conversion of language in a project
conversion of language in a project  how can we convert the database code in the project dynamically
Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   Hi, Please see NSString to float conversion
object conversion - Java Beginners
object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your.../java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman
Conversion of unicode to its corresponding character
Conversion of unicode to its corresponding character  i have a string of unicodes e.g String s="\c0059\c0049\c3000" .. i need code for converting these unicodes to its corresponding alphabets.. pls if possible rep asap as i need
Conversion - Development process
is the theory of conversion from java to .NET? How it is done?   Hi... Conversion Assistant (JLCA). Code that calls Java APIs can convert to comparable C# code... to a topic with guidelines for modifications needed to finish the conversion
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   HI, Use the following code: NSScanner *strXpos
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
 

 

 

DMCA.com