0% found this document useful (0 votes)
23 views6 pages

Oop Assinment#1: Submitted By: Adnan Haider REG NO: SP20-BSE-037 Section: Bse 3B DATE: 26-03-2020

Uploaded by

Adnan Aadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Oop Assinment#1: Submitted By: Adnan Haider REG NO: SP20-BSE-037 Section: Bse 3B DATE: 26-03-2020

Uploaded by

Adnan Aadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OOP ASSINMENT#1

SUBMITTED BY: ADNAN HAIDER


REG NO: SP20-BSE-037
SECTION: BSE 3B
DATE: 26-03-2020
Q.1: Print “Array contains 6” if array has 6 at first or last index.

package firstlast6;

public class Firstlast6 {

public static void main(String[] args) {

int arr[]={6,2,3,5,1,6};

if(arr[0] == 6 || arr[arr.length-1] == 6)

System.out.println("Array contains 6:");

else

System.out.print("not contains 6");

}}}
Q.2: Print “same” if the first and last index are same
package same;

public class Same {

public static void main(String[] args) {

int arr[]={6,2,3,5,1,6};

if(arr[0] == 6 && arr[arr.length-1] == 6)

System.out.println("same:");

else

System.out.print("not same");

}}
Q.3 Create a new array in which all the values are left rotate:
public class Rotate {

void leftRotate(int arr[], int d, int n)

for (int i = 0; i < d; i++)

leftRotatebyOne(arr, n);

void leftRotatebyOne(int arr[], int n)

int i, temp;

temp = arr[0];

for (i = 0; i < n - 1; i++)

arr[i] = arr[i + 1];

arr[n-1] = temp;

/* utility function to print an array */

void printArray(int arr[], int n)

for (int i = 0; i < n; i++)

System.out.print(arr[i] + " ");

// Driver program to test above functions

public static void main(String[] args)

{
Rotate rotate = new Rotate();

int arr[] = { 1, 2, 3, 4, 5, 6, 7 };

rotate.leftRotate(arr, 2, 7);

rotate.printArray(arr, 7);

Q.4 Add 10 to all the indexes of the array and save the result in new array and
display that new array

public class Add10 {

public static void main(String[] args) {

int arr[]={2,4,3,5,7};

for(int i = 0; i <arr.length; i++)

arr[i]=i+10;

System.out.println("by adding 10 to each"+arr);


}

You might also like