Respuesta :
Answer:
Explanation:
Take note to avoid Indentation mistake which would lead to error message.
So let us begin by;
import java.util.*; ------ using Java as our programming language
class Mutation {
public static boolean alternatingSort(int n , int[] a)
{
int []b = new int[n];
b[0]=a[0];
int j=1,k=0;
for(int i=1;i<n;i++)
{
if(i%2==1)
{
b[i]=a[n-j];
j++;
}
else
b[i]=a[++k];
}
for(int i=0;i<n;i++)
{
System.out.print(b[i]+" ");
}
System.out.print("\n");
for(int i=1;i<n;i++)
{
if(b[i]<=b[i-1])
return false ;
}
return true;
}
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int []a = new int [n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println(alternatingSort(n,a));
}
}
This code should give you the desired result (output).
The program is an illustration of Arrays.
Arrays are variables that are used to hold multiple values using one variable name
The program in Java, where comments are used to explain each line is as follows:
import java.util.Scanner;
public class Main {
//This defines the alternatingSort function
public static boolean alternatingSort(int n , int[] a){
//This creates an array b
int b[] = new int[a.length];
//This populates the first element of array b
b[0]=a[0];
//This initializes two counter variables
int count1 =1,count2 = 0;
//This iterates from 1 to n - 1
for(int i=1;i<a.length;i++){
//This populates array b for odd indices
if(i%2==1){
b[i]=a[n-count1];
count1++;
}
//This populates array b for even indices
else{
b[i]=a[++count2];
}
}
//This iterates from 0 to n - 1
for(int i=0;i<a.length;i++){
//This prints the elements of array b
System.out.print(b[i]+" ");
}
//This prints a new line
System.out.println();
//This iterates from 1 to n - 1
for(int i=1;i<a.length;i++){
//This checks if the elements of array b are strictly in ascending order
if(b[i]<=b[i-1]){
return false ;
}
}
return true;
}
//The main function begins hers
public static void main (String[] args) {
//This creates a Scanner object
Scanner input = new Scanner(System.in);
//This gets input for the length of the array
int n= input.nextInt();
//This creates the array a
int a[] = new int [n];
//The following iteration populates array a
for(int i=0;i<n;i++){
a[i]=input.nextInt();
}
//This calls the alternatingSort function
System.out.println(alternatingSort(n,a));
}
}
Read more about arrays at:
https://brainly.com/question/15683939