0
How to reverse an array
My code is working but whenever i enter a scanner it errors. What I wanted should be: Ex.1 Input: 2 (size of the array) 50 100 Output: 100 50 Ex2: Input: 3 5 11 27 Output: 27 11 5 This is my code: https://code.sololearn.com/c0a788a21a0A
7 Respostas
+ 3
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner input= new Scanner (System.in);
System.out.println("Enter size");
int my_array = input.nextInt();
System.out.println("Enter numbers to reverse");
int[] intArray =new int[my_array];
for(int i=0;i<intArray.length;i++)
{
intArray[i]=input.nextInt();
}
for(int i=intArray.length-1;i>=0;i--)
System.out.println(intArray[i]);
}
}
//Is this your expected output?
+ 1
There were multiple errors in your program u need to use the primitive datatype for the declaration not the wrapper class
And you need to loop over the inputs otherwise it will take default values that is 0
+ 1
Martin Taylor check now