Lab Assignment 1
Lab Assignment 1
Lab Assignment 1
LABSHEET 1
MALAVIKA SREEJITH
AM.EN.U4ELC22053
1. import java.util.Scanner;
while(start_index<end_index)
{
int temp = array[start_index];
array[start_index] = array[end_index];
array[end_index] = temp;
start_index ++;
end_index --;
}
}
public void printArray()
{
for(int num : array)
{
System.out.print(num + " ");
}
System.out.println();
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter size of array : ");
int size = scanner.nextInt();
int [] arr = new int [size];
for(int i = 0; i<size;i++)
{
System.out.println("Enter element to be entered at element "+i+" :
");
arr[i] = scanner.nextInt();
}
System.out.println("Original Array :");
MyREverse MyObj = new MyREverse(arr);
MyObj.printArray();
MyObj.reverse(arr);
System.out.println("Reversed array :");
MyObj.printArray();
scanner.close();
}
}
Output:
bubbleSort(arr);
Output:
3.
public class Book {
private String title;
private String author;
private String publisher;
private int bookId;
private int edition;
private String ISBN;
public Book(String title, String author, String publisher, int bookId, int
edition, String ISBN) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.bookId = bookId;
this.edition = edition;
this.ISBN = ISBN;
}
Book book = new Book("A Feast for the crows", "George R R Martin",
"Fort Publications", 12345, 1, "978-3-16-148410-7");
book.displayBookDetails();
book.setEdition(2);
book.setPublisher("Swen Publications");
Output:
4.
import java.util.Scanner;
import java.util.Arrays;
rearrangeZigZag(arr);
scanner.close();
}
}
Output:
5.
import java.util.Scanner;
import java.util.Arrays;
int rotations = d % n;
return rotatedArray;
}
scanner.close();
}
}
Output: