Wednesday, September 4, 2019

BlueJ Program of Reversing Elements of Array Without Dummy Array


In this BlueJ Program we will take 10 values and the values will be reversed without the help of any external location. 



Take 10 numbers in an array and reverse the numbers in the same array

Like

Original

2
3
4
5
6
7
8
9
10
11



After Reverse

11
10
9
8
7
6
5
4
3
2


import java.util.Scanner;
class Star
{
int i,j,t,arr[]=new int [10];
Scanner sc=new Scanner(System.in);
public void read()
{
for(i=0;i< =9;i++)
{
     System.out.print("\nvalue: ");
     arr[i]=sc.nextInt();
 }
 System.out.println("\nOriginal Array");
 for(i=0;i< =9;i++)
 System.out.print(" "+arr[i]);
 j=9;
 for(i=0;i< =9/2;i++)
 {
     t=arr[i];
     arr[i]=arr[j];
     arr[j]=t;
     j--;
  }
  System.out.println("\nModified Array");
 for(i=0;i< =9;i++)
 System.out.print(" "+arr[i]);      
}
public static void main(String args[])
{
 Star ob=new Star();
 ob.read();
  }
}


Related Post: BlueJ Programs on Numeric Array

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner