0

This is blank not showing output why ?

package arr; public class Alar { public static void main(String[] args) { int arr[]= {10,20,30,40,50}; int n=5; other.find(arr,n); } } class other { static void find(int arr[],int n) { int temp=arr[n-1]; for(int i=0;i<=n-2;) { arr[i]=arr[i+1]; } arr[n-1]=temp; for(int i=0;i<n;i++) { System.out.print(arr[i]); } } } This is not showing any output input 10,20,30,40,50 output will be 20,30,40,50,10

12th Jun 2021, 12:34 AM
Sachin Saxena
Sachin Saxena - avatar
4 Answers
+ 1
what is the purpose of the first line? it makes java not recognizing your classes: you must remove it ^^ the 'find' method of 'other' class lacks of i incrementation in first loop... you are assigning the same value to 'temp' than the one you assign from temp after second loop: 'temp' should be initialized with arr[0]... your second loop lacks of comma separator outputed after each values except the last... working code: public class Alar { public static void main(String[] args) { int arr[]= {10,20,30,40,50}; int n=5; other.find(arr,n); } } class other { static void find(int arr[],int n) { int temp=arr[0]; for(int i=0;i<=n-2;i++) { arr[i]=arr[i+1]; } arr[n-1]=temp; for(int i=0;i<n;i++) { System.out.print(arr[i]); if (i<n-1) System.out.print(","); } } } however, you doesn't take input from user but hardcode the array used ;P
12th Jun 2021, 1:06 AM
visph
visph - avatar
+ 1
couldn't explain more briefly than what I do previously ^^
12th Jun 2021, 1:23 AM
visph
visph - avatar
0
I didn't understand explain briefly
12th Jun 2021, 1:21 AM
Srinibash Nayak
0
You have 2 error 1 bad temp initialization 2 do not increment i in the for cicle (infinite loop)
12th Jun 2021, 11:07 AM
Ciro Pellegrino
Ciro Pellegrino - avatar