🔒 Closed Inverter without if statement

Status
Not open for further replies.

Princess Serrano

Honorary Poster
public class Main {

private int [] binary = {0,1};

private void invert(String input) {
String inverted = "";

for (char a : input.toCharArray()) {
inverted += binary[(Character.getNumericValue(a)+1) % 2];
}
System.out.println("Original: " + input + "\n" +
"Inverted: " + inverted);
}

public static void main(String... args) {
Main main = new Main();
main.invert("101010");
}
}


Skl. Hahaha
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 355
    Views
  • 4
    Participants
Last reply from:
MenofUnderstanding

Trending Topics

Online now

Members online
1,160
Guests online
1,639
Total visitors
2,799

Forum statistics

Threads
2,287,024
Posts
29,041,868
Members
1,216,346
Latest member
kncks_
Back
Top