+ 1

Why this code giving output zzzzzzzzz if input is sololearn

import java.util.Scanner; public class Program { public static void main(String[] args) { char [] z = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' '}; char [] a = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; Scanner sc = new Scanner(System.in); String n = sc.nextLine(); char c='a'; String w =""; for(int j=0;j<=n.length()-1;++j){ for(int i=0;i<=25;++i){ if(n.charAt(j)==z[i]){ c = z[26-i]; } if(n.charAt(j)==a[i]){ c=a[26-1];} if(n.charAt(j)==' '){ c=' '; } } w=c+w; } System.out.print(w); } }

29th May 2020, 3:27 PM
Shivam Rawal
5 Antworten
+ 3
In line 18 there is c = a[26-1] instead of 26-i. Plus, it should be 25, as I suspect.
29th May 2020, 3:38 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Please show the link to your code, do not paste your code in the question, it's hard to read.
29th May 2020, 3:29 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Tysm
29th May 2020, 3:40 PM
Shivam Rawal
0
K
29th May 2020, 3:30 PM
Shivam Rawal
29th May 2020, 3:31 PM
Shivam Rawal