Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myClass {
- /** this method tests if each two consecutive components
- * of the array are sorted. And once at least one set
- * of two consecutive components don't fit the condition
- * the computer gets that the array isn't sorted
- */
- public static boolean isSorted(double[] array) {
- boolean sort = false;
- for (int i=0; i<array.length; i++){
- if (array[i]<= array[i+1]){
- sort = true;
- } else {
- sort = false;
- break;
- }
- }
- return sort;
- }
- public static double[] append(double[] param1, double[] param2) {
- double[] newArray = new double[param1.length + param2.length];
- for (int i = 0; i < newArray.length; i++) {
- if (i < 3) {
- newArray[i] = param1[i];
- } else {
- newArray[i] = param2[i-3];
- }
- }
- return newArray;
- }
- public static void printValues(double[] values) {
- System.out.print("[");
- for (int j=0; j<values.length-1; j++) {
- System.out.print(values[j]);
- System.out.print(", ");
- }
- System.out.print(values[values.length-1]);
- System.out.println("]");
- }
- public static void main(String[] args) {
- double[] array1 = {2,3,7};
- double[] array2 = {4,2,6};
- double[] appended = append(array1, array2);
- printValues(appended);
- boolean appendedSort = isSorted(appended);
- if (appendedSort) {
- System.out.print("The appended array is sorted!");
- } else {
- System.out.print("The appended array isn't sorted!");
- }
- }
- }
Add Comment
Please, Sign In to add comment