Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  myProgTest
Language: JAVA
Code:

import java.io.*;
public class swapString
{
     public static void main(String args[]) throws IOException
     {
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
             System.out.println("Enter a sentence");
             String str=br.readLine();
             int x=0,y=0;
             String strNew="";
            for(int i=0;i<str.length()-1;i=i+2)//swap alternate characters
              {
                  x=str.charAt(i);
                  y=str.charAt(i+1);
                  strNew=strNew+y+x;
              }
     System.out.println("Encrypted sentence is: "+strNew);
    }
}
Comments: