0

my code should print numbers in reverse array
its not have error
but the lest for statement its not print array in reverse order

import java .util.Scanner;
public class R {

    public static void main (String [] args){
    	Scanner input=new Scanner(System.in);
    	int size;
    	System.out.println("Size ");
    	size=input.nextInt();
    	int [] array=new int [size];
    	System.out.println("enter element ");
    	for(int i=0;i<array.length;i++)
    		array[i]=input.nextInt();
    			System.out.println(" element of array is ");
    			for(int i=0;i<array.length;i++)
    		System.out.println(" "+array[i]);
int arrayb[]=new int[size];
 for(int i=0;i<array.length;i++)
			 {            arrayb[i] = array[i];        }
			 	System.out.println(" element of array befor reserved ");
			 	for(int i=0;i<arrayb.length;i++)
    		System.out.println(" "+arrayb[i]);
System.out.println(" element of array after reserved ");
for(int i=arrayb.length-1;i<=0;i--)
System.out.println(" "+arrayb[i]);
}}
2
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by NormR1
Featured Replies
  • 1

    What is the value of the loop's termination expression the first time the code is executed? Is it true or false? Read this to see what I am talking about: [url]http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html[/url] Read More

0

the lest for statement its not print array in reverse order

Please post the program's output that shows the problem.

You need to edit your code and properly align the statements.
The messy way you have posted the code makes it very hard to read.

You should align the } vertically beneath the statement with the starting {
Do NOT put two }}s on the same line.
Do not put a statement on the same line following a {

Edited by NormR1: n/a

0

here i think is problem

for(int i=arrayb.length-1;i<=0;i--)
System.out.println(" "+arrayb[i]);

output

--------------------Configuration: <Default>--------------------
Size 
2
enter element 
1
2
 element of array is 
 1
 2
 element of array befor reserved 
 1
 2
 element of array after reserved 

Process completed.

Edited by programing: n/a

0

Copy the for loop's termination expression here and explain how you think it is working.

0
for(int i=arrayb.length-1;i<=0;i--)

loor start from the last elemnt to first element in array

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.