Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 960311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:09:49+00:00 2026-05-16T01:09:49+00:00

String input = txtInput.getText(); char[] charArray = input.toCharArray(); char[] flipArray = null; System.out.println(charArray.length); for

  • 0
String input = txtInput.getText();

char[] charArray =  input.toCharArray();
char[] flipArray = null;
System.out.println(charArray.length);
for (int i = 0; i < charArray.length ; i++) {
    System.out.println(charArray[i]);

sorry if the code doesn’t make much sense.

charArray is taken from a JTextField .

So the code should do something like this.

  1. Takes in a message and flip every 2 characters. That is, the 1st and 2nd characters are switched and the 3rd and 4th are switched etc;
  2. For example, “You can’t read my message!” will be “oY uac’n terdam yemssga!e” after encryption;

charArray would be the Message that says “You can’t read my message!”
flipArray would be carrying the message that says “oY uac’n terdam yemssga!e”

How do I write a loop that puts it in such that…

charArray[0] = flipArray[1]
charArray[1] = flipArray[0]
charArray[2] = flipArray[3]
charArray[3] = flipArray[2]
charArray[4] = flipArray[5]
charArray[5] = flipArray[4]

The value of charArray is taken from a JTextField.

I’m doing this on NetBeans IDE 6.5.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:09:49+00:00Added an answer on May 16, 2026 at 1:09 am

    Tomfoolery.

    for( int i = 0; i < charArray.length; i+= 2 )
    {
       charArray[i] = flipArray[i+1];
       charArray[i+1] = flipArray[i];
    }
    

    I’m assuming that 0,1 goes to 1,0, 2,3 to 3,2, etc.

    I think this is what you really mean:

    String input = ...
    StringBuilder builder = new StringBuilder();
    
    for( int i = 0; i < input.length(); i += 2 )
    {
       //guard against odd text lengths
       if( i+1 < input.length() )
       {
          builder.append( input.charAt(i+1) );
       }   
       builder.append( input.charAt(i) );
    }
    
    String flippedText = builder.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static boolean palindrome(String input, int i, int j) { if (i >= j)
I have the following code: string input = ç; string normalized = input.Normalize(NormalizationForm.FormD); char[]
How can I specify the length of string input parameters of a stored procedure
For example i have a string input int,can i declare a variable base on
void get_english_input() { string input = ; stringstream my_string(input); int ft; double in; while(true)
String input = key1=value1&key2=value2&key3=value3&key4=value4&key5=value5; How can I store the key-value pairs into a HashMap
string input = Hello World!; string pattern = (World|Universe); string replacement = $1; string
I have a string input from which I need to extract simple information, here
I have a string input = "maybe (this is | that was) some ((nice
I have a string input that i do not know whether or not is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.