why this error>. error name: printans(ans) cannot find symbol, why?? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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]); } } }

18th Jun 2023, 9:48 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
16 Antworten
+ 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
22nd Jun 2023, 12:11 PM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
+ 6
People are more likely to test your code if you LINK IT instead of pasting it into the description box.
18th Jun 2023, 10:15 AM
Lisa
Lisa - avatar
+ 6
18th Jun 2023, 12:01 PM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 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..
18th Jun 2023, 3:42 PM
Jayakrishna 🇮🇳
+ 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)!
18th Jun 2023, 12:08 PM
Dragon RB
Dragon RB - avatar
+ 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! ✅✅✅ =============================
18th Jun 2023, 10:26 AM
Dragon RB
Dragon RB - avatar
+ 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??
22nd Jun 2023, 8:58 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
+ 1
Show is the update code..!, if not solved...
22nd Jun 2023, 11:38 AM
Jayakrishna 🇮🇳
+ 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..
22nd Jun 2023, 11:50 AM
Jayakrishna 🇮🇳
+ 1
Jayakrishna 🇮🇳 Stiil not working Yes I think, I have changed some setting of my ide I have to reinstall it!
22nd Jun 2023, 12:03 PM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
0
Lisa how to link? I am really new to this application
18th Jun 2023, 11:40 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
0
Dragon RB I want to pass Ans only! I tried rest of the ways, still not working
18th Jun 2023, 11:41 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
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 =========================
22nd Jun 2023, 10:59 AM
Dragon RB
Dragon RB - avatar
0
Shubham Swaraj 161 Also, please post your question in the Q&A Discussions to get more people see it.
22nd Jun 2023, 11:04 AM
Dragon RB
Dragon RB - avatar
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
22nd Jun 2023, 11:38 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
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..
22nd Jun 2023, 12:05 PM
Dragon RB
Dragon RB - avatar