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
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
+ 1
couldn't explain more briefly than what I do previously ^^
0
I didn't understand explain briefly
0
You have 2 error
1 bad temp initialization
2 do not increment i in the for cicle (infinite loop)