Skip to main content
Commonmark migration
Source Link

#Java 8, 159 158 bytes

Java 8, 159 158 bytes

n->s->{for(int i=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((j=x.indexOf(s[i])+n)>=n)s[i]=x.charAt(j%x.length());} 

-1 byte thanks to @OlivierGrégoire modifying the input-array instead of printing directly.

Explanation:

Try it online.

n->s->{ // Method with integer and character-array parameters, and no return-type for(int i=s.length,j;i-->0;) // Loop over the input character-array with index for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";")) // Inner loop over the qwerty-lines if((j=x.indexOf(s[i])+n)>=n) // If the current qwerty-line contains the character // Set `j` to the index of this character on that line + input `n` s[i]=x.charAt(j%x.length());} // Replace the character at index `i` // with the new character (at index `j` modulo length_of_qwerty_line) 

#Java 8, 159 158 bytes

n->s->{for(int i=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((j=x.indexOf(s[i])+n)>=n)s[i]=x.charAt(j%x.length());} 

-1 byte thanks to @OlivierGrégoire modifying the input-array instead of printing directly.

Explanation:

Try it online.

n->s->{ // Method with integer and character-array parameters, and no return-type for(int i=s.length,j;i-->0;) // Loop over the input character-array with index for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";")) // Inner loop over the qwerty-lines if((j=x.indexOf(s[i])+n)>=n) // If the current qwerty-line contains the character // Set `j` to the index of this character on that line + input `n` s[i]=x.charAt(j%x.length());} // Replace the character at index `i` // with the new character (at index `j` modulo length_of_qwerty_line) 

Java 8, 159 158 bytes

n->s->{for(int i=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((j=x.indexOf(s[i])+n)>=n)s[i]=x.charAt(j%x.length());} 

-1 byte thanks to @OlivierGrégoire modifying the input-array instead of printing directly.

Explanation:

Try it online.

n->s->{ // Method with integer and character-array parameters, and no return-type for(int i=s.length,j;i-->0;) // Loop over the input character-array with index for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";")) // Inner loop over the qwerty-lines if((j=x.indexOf(s[i])+n)>=n) // If the current qwerty-line contains the character // Set `j` to the index of this character on that line + input `n` s[i]=x.charAt(j%x.length());} // Replace the character at index `i` // with the new character (at index `j` modulo length_of_qwerty_line) 
added 156 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 8, 159159 158 bytes

n->s->{int i;forfor(charint c:si=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((i=xj=x.indexOf(cs[i])+n)>=n)System.out.print(xs[i]=x.charAt(i%xj%x.length()));} 

-1 byte thanks to @OlivierGrégoire modifying the input-array instead of printing directly.

Explanation:

Try it online.Try it online.

n->s->{  // Method with integer and character-array parameters, and no return-type for(int i; i=s.length,j;i-->0;)  // Index-integer  for(char c:s) // Loop over the input character-array with index for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))   // Inner loop over the qwerty-lines if((i=xj=x.indexOf(cs[i])+n)>=n)   // If the current qwerty-line contains the character   // Set `i``j` to the index of this character on that line + input `n` System.out.print(xs[i]=x.charAt(i%xj%x.length()));}   // Replace the character at index `i` //  And printwith the new character (at index `i``j` modulo length_of_qwerty_line) 

#Java 8, 159 bytes

n->s->{int i;for(char c:s)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((i=x.indexOf(c)+n)>=n)System.out.print(x.charAt(i%x.length()));} 

Explanation:

Try it online.

n->s->{  // Method with integer and character-array parameters, and no return-type int i;  // Index-integer  for(char c:s) // Loop over the input character-array for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))   // Inner loop over the qwerty-lines if((i=x.indexOf(c)+n)>=n)   // If the current qwerty-line contains the character   // Set `i` to the index of this character on that line + input `n` System.out.print(x.charAt(i%x.length()));} //  And print the character at index `i` modulo length_of_qwerty_line 

#Java 8, 159 158 bytes

n->s->{for(int i=s.length,j;i-->0;)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((j=x.indexOf(s[i])+n)>=n)s[i]=x.charAt(j%x.length());} 

-1 byte thanks to @OlivierGrégoire modifying the input-array instead of printing directly.

Explanation:

Try it online.

n->s->{ // Method with integer and character-array parameters, and no return-type for(int i=s.length,j;i-->0;)  // Loop over the input character-array with index for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";")) // Inner loop over the qwerty-lines if((j=x.indexOf(s[i])+n)>=n) // If the current qwerty-line contains the character // Set `j` to the index of this character on that line + input `n` s[i]=x.charAt(j%x.length());}   // Replace the character at index `i` // with the new character (at index `j` modulo length_of_qwerty_line) 
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 8, 159 bytes

n->s->{int i;for(char c:s)for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";"))if((i=x.indexOf(c)+n)>=n)System.out.print(x.charAt(i%x.length()));} 

Explanation:

Try it online.

n->s->{ // Method with integer and character-array parameters, and no return-type int i; // Index-integer for(char c:s) // Loop over the input character-array for(String x:"1234567890;QWERTYUIOP;ASDFGHJKL;ZXCVBNM".split(";")) // Inner loop over the qwerty-lines if((i=x.indexOf(c)+n)>=n) // If the current qwerty-line contains the character // Set `i` to the index of this character on that line + input `n` System.out.print(x.charAt(i%x.length()));} // And print the character at index `i` modulo length_of_qwerty_line