Skip to main content
2 of 3
added 156 characters in body
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#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) 
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394