+ 2
why this error>. error name: printans(ans) cannot find symbol, why??
import java.util.*; class rotateKsteps{ public static void main(){ int arr[]={1,2,3,4,5,6,7}; int k =3; turn(arr,k); printans(ans); } static int[] turn(int arr[],int k){ int n = arr.length; int ans[]=new int[n]; int j =0; for(int i=n-1;i>n-k-1;i--){ ans[j++]=arr[i]; } for(int i=0;i<n-k;i++){ ans[j++]=arr[i]; }return ans; } static int[] printans(int ans[]){ for (int i =0;i<ans.length;i++){ System.out.println(ans[i]); } } }
16 Answers
+ 1
Dragon RB
Still showing samr error, I wish could share screenshots here
Btw
I have used (String args[ ] ) to run a lot of programs and it worked!
I guess I have misconfigured my IDE
+ 6
People are more likely to test your code if you LINK IT instead of pasting it into the description box.
+ 6
Shubham Swaraj 161
Share your code by following these steps:
https://code.sololearn.com/Wek0V1MyIR2r/?ref=app
+ 5
Shubham Swaraj 161 From your profile, you can see code bits section. There you can find (+) button, tap on it. Select Java and write code. From option save. And besides that you can find share button ( like a 3 dots graph).. , tap on it and select copy to clip board. Now you can paste link here in reply. Like above @Hasnain posted code, may it about sharing from web. Am about sharing from mobile. Try both..
But actually your code has no proper main method so it won't run..
declare array as 'ans' and pass 'ans' to methods..
+ 4
Shubham Swaraj 161 It's not possible to pass variable (as parameter) to the method in your code, without it being created and declared in the main method! The "ans" in the main method of your code is not declared/created, so it does not exist in the main method. You need to declare/create it in the main method before using it(in the main method)!
+ 3
=============================
โโHere are some mistakes that I found in your code:โโ
=============================
1๏ธโฃ. Every non-void type method requires a return type! You haven't return anything in the printans method.
=============================
2๏ธโฃ. In the main method, `ans` isn't declared and it doesn't exist! Did you meant to pass the array `arr` to the method?
=============================
3๏ธโฃ. The line where you called the main method is NOT correct:
`public static void main() {} //Not correct! โโโ`
Instead, it should be:
`public static void main(String[] args) {} //Correct! โ
โ
โ
=============================
+ 2
Jayakrishna ๐ฎ๐ณ
Lisa
Dragon RB
Hasnain [ACTIVE CHALLENGER]
though
I have resolved the problem
But I am stucked with my vsCode
Even if I am writing small simpler code say Hello world, its not running in my terminal, but is running in every online compiler even in sololearn !
But
In my laptop, vscode terminal is throwing error :
String [ ] cannot be be converted to string ,
?? for correct programs
Why this is happening??
+ 1
Show is the update code..!, if not solved...
+ 1
Not possible..
May be you are missing [ ] in String arg[ ]
Do check again...
You may changed ant settings.. ! Simply uninstall and reinstall again..
Or try reset settings.
But i guess, it's programming error..
๐คIf not work, then sharing screenshot may help to find error..
+ 1
Jayakrishna ๐ฎ๐ณ Stiil not working
Yes I think, I have changed some setting of my ide
I have to reinstall it!
0
Lisa how to link? I am really new to this application
0
Dragon RB I want to pass Ans only! I tried rest of the ways, still not working
0
Shubham Swaraj 161 Please send your code here so we can run and fix it, if it works on SoloLearn but not on your terminal, I can run it on my IDE.. I haven't use the IDE you are using yet, and I would like to see your code here..
If your computer says String[] cannot be converted to String, it is because maybe you attempted to assign a string array to a normal string, or a normal string to a string array.
When declaring a variable, you need to define its type and assign it with the correctsponding type. Y'know?
For example:
String arr[]= "Hello" //NOT CORRECT
String h = "Hello".toCharArray() //NOT CORRECT
=========================
String arr[] = new String[size];/ String arr[] = {"Hello","World"}; //Correct
=========================
0
Shubham Swaraj 161 Also, please post your question in the Q&A Discussions to get more people see it.
0
Dragon RB
Import java.util.*;
public class hello{
public static void main(String args[ ]) {
System.out.println("Hello World") ;
}
}
Even this code is throwing the same error in terminal
I am using VsCode ide
This code is correct
Running in every online ide
But not in my system ide. ??
Why ?
Please help man
0
No no no Shubham Swaraj 161 , the main method should be like this:
public static void main(String[] args){}
Some beginners keep getting confused at the calling main method stuff, but if you keep learning and practicing, this would be a piece of cake. Almost every IDE provide a code template(What I mean is they already executed some line of code to make it run) for you to get started.
The String should be followed with brackets. My IDE would make the main method for me if there are no main method in my Java program.
And please, when no other parts from a Java module is used, you do not have to import anything.. Like, when you need to get user input, import the Scanner class..