Java Program to separate the Individual Characters from a String

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

Program:

  1. public class IndividualCharacters  
  2. {  
  3.     public static void main(String[] args) {  
  4.         String string = “characters “;  
  5.   
  6.         //Displays individual characters from given string  
  7.         System.out.println(“Individual characters from given string: “);  
  8.   
  9.         //Iterate through the string and display individual character  
  10.         for(int i = 0; i < string.length(); i++){  
  11.             System.out.print(string.charAt(i) + ” “);  
  12.         }  
  13.     }  
  14. }  

Output:

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

Leave a Comment