+ 1

Code throwing error that m can not be found

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

18th May 2020, 12:31 PM
Shivam Rawal
3 Answers
0
Idk if that fixes your problem but in the first for loop you used j as an iteration variable but used i in the body.
18th May 2020, 1:53 PM
Jnn
Jnn - avatar
0
Did you catch it? When you share a code, tell us what you are trying to do, what is the input like etc. This would help the community to help you solve your problem soon.
18th May 2020, 1:55 PM
Avinesh
Avinesh - avatar
0
It's showing NosuchElement exception
18th May 2020, 2:27 PM
Shivam Rawal