Q:

Java Program to separate the Individual Characters from a String

belongs to collection: Java String Programs

0

In this program, we need to separate each character from the string.

CHARACTERS

C H A R A C T E R S

In computer science, collection of characters including spaces is called as string. To separate an individual character from the string, individual characters are accessed through its index.

Algorithm

  • STEP 1: START
  • STEP 2: DEFINE String string = "characters "
  • STEP 3: PRINT "Individual characters from given string: "
  • STEP 4: SET i=0. REPEAT STEP 5 to STEP 6 UNTIL i<string.length()
  • STEP 5: PRINT string.charAt(i)
  • STEP 6: i=i+1
  • STEP 7: END

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

public class IndividualCharacters  
{  
    public static void main(String[] args) {  
        String string = "characters ";  
  
        //Displays individual characters from given string  
        System.out.println("Individual characters from given string: ");  
  
        //Iterate through the string and display individual character  
        for(int i = 0; i < string.length(); i++){  
            System.out.print(string.charAt(i) + " ");  
        }  
    }  
}  

Output:

Individual characters from given string:
c h a r a c t e r s

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java Program to swap two string variables without ... >>
<< Java Program to find the number of the words in th...