package Assignment;
public class Assignment01 {
public static void main(String[] args) {
int[] array = { 10, 20, 30, 40, 50 };
for (int n : array) {
System.out.printf("%d ", n);
}
}
}
package Assignment;
public class Assignment02 {
/**
* @param args
*/
public static void main(String[] args) {
char[] array = {'n', 'e', 'u', 's', 'o', 'f', 't', 'e', 'd', 'u', 'c', 'a', 't', 'i', 'o', 'n'};
char[] array1 = array;
}
}
package Assignment;
import java.util.Arrays;
public class Assignment03 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = {1,6,2,3,9,4,5,7,8};
Arrays.sort(array);
for (int n : array) {
System.out.printf("%d ", n);
}
}
}
package Assignment;
public class Assignment04 {
/**
* @param args
*/
public static void main(String[] args) {
double array[][] = new double[5][4];
for (int row = 0; row < 5; row++) {
for (int column = 0; column < 4; column++) {
array[row][column] = (row + column / 10.0);
System.out.printf("%f ", array[row][column]);
}
System.out.println();
}
}
}
package Assignment;
public class Assignment05 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = {18, 25, 7, 36, 13, 2, 89, 63};
int max_idx = 0;
for (int n = 1; n < array.length; n++) {
if (array[max_idx] < array[n]) {
max_idx = n;
}
}
System.out.println(max_idx);
System.out.println(array[max_idx]);
}
}
package Assignment;
public class Assignment06 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = {6, 5, 4, 3, 2, 1, 0};
int temp = -1;
for (int n = 0; n < array.length / 2; n++) {
temp = array[n];
array[n] = array[array.length - 1 - n];
array[array.length - 1 - n] = temp;
}
for (int n : array) {
System.out.printf("%d ", n);
}
System.out.println();
}
}
package Assignment;
public class Assignment07 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = new int[10];
int number = 0;
for (int n = 0; n < array.length; n += 2) {
array[n] = number;
array[n + 1] = number;
number++;
}
int[] index = new int[array.length];
for (int n = 0; n < index.length; n++) {
index[n] = n;
}
for (int n = 0; n < array.length; n++) {
int target = array[n];
for (int m = n + 1; m < array.length; m++) {
if (array[m] == target) {
index[m] = -1;
}
}
}
int _size = 0;
for (int n = 0; n < index.length; n++) {
if (index[n] != -1) {
_size++;
}
}
int[] newArray = new int[_size];
int _index = 0;
for (int n = 0; n < index.length; n++) {
if (index[n] != -1) {
newArray[_index] = array[index[n]];
_index++;
}
}
for (int n : newArray) {
System.out.printf("%d ", n);
}
System.out.println();
}
}
package Assignment;
public class Assignment08 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = {-10, 2, 3, 246, -100, 0, 5};
int sum = 0;
int min = array[0];
int max = array[0];
for (int n = 0; n < array.length; n++) {
sum += array[n];
if (min > array[n]) min = array[n];
if (max < array[n]) max = array[n];
}
double average = sum / array.length;
System.out.println(sum);
System.out.println(average);
System.out.println(min);
System.out.println(max);
}
}
package Assignment;
public class Assigmnemt09 {
/**
* @param args
*/
public static void main(String[] args) {
int fibArray[] = new int[20];
fibArray[0] = 1;
fibArray[1] = 1;
for (int n = 2; n < 20; n++) {
int temp = fibArray[n - 1];
fibArray[n] = fibArray[n - 2] + fibArray[n - 1];
fibArray[n - 1] = temp;
}
for (int n : fibArray) {
System.out.printf("%d ", n);
}
System.out.println();
}
}
package Assignment;
import java.util.Random;
public class Assignment10 {
/**
* @param args
*/
public static void main(String[] args) {
int[] array = new int[10];
Random random = new Random();
for (int n = 0; n < array.length; n++) {
array[n] = random.nextInt(100);
}
for (int n : array) {
System.out.printf("%d ", n);
}
System.out.println();
for (int n = 0; n < array.length; n++) {
for (int m = n; m < array.length; m++) {
if (array[n] > array[m]) {
int temp = array[n];
array[n] = array[m];
array[m] = temp;
}
}
}
for (int n : array) {
System.out.printf("%d ", n);
}
System.out.println();
}
}