here is a code i wrote in java, I'm still a beginner in a java so if this is a noob mistake please rectify it and also provide alternative solutions for reading the string and converting it to char array
import java.util.Scanner;
import java.io.*;
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
char[] c = str.toCharArray(str);
int x=0,y=0;
for(int i=0;i<=str.length;i++)
{
if(c[i]=='L')
{
x=x+1;
}
else if(c[i]=='R')
{
x=x-1;
}
else if(c[i]=='U')
{
y=y-1;
}
else if(c[i]=='D')
{
y=y-1;
}
}
System.out.println(x+""+y);
}
}
I'm getting the following error
10: error: method
toCharArrayin class String cannot be applied to given types;no arguments String actual and formal argument lists differ in length 12: error: cannot find symbol
variable length variable str of type String