1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kotykmax [81]
4 years ago
12

write a function issorted() that accepts an array of real numbers arr and an integer n as arguments, where n is the size of arr.

The function properly reads n integers into the array arr,then finds and returns whether the items of the array are sorted in ascending order.
Computers and Technology
1 answer:
lesantik [10]4 years ago
7 0

Answer:

Here is code in java.

import java.util.*;

class Main

{

//main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

       int m;

        // scanner object to read input from user

       Scanner ss=new Scanner(System.in);

       System.out.println(" size  of the array:");

       //read the size of the array

        m=ss.nextInt();

        // create array of the given size

        float arr[]=new float[m];

        /* call function to check whether input are in the ascending sorted order or not */

        Boolean res= issorted(arr,m);

       

      // print the result

       System.out.println("array in the ascending sorted order  : "+res);

     

       

   }catch(Exception ex){

       return;}

}

 // function to check whether input are in the ascending sorted order or not

public static boolean issorted(float[] arr,int n)

{

    int i,j;

    float d;

    Boolean flag=true;

    Scanner ss=new Scanner(System.in);

    System.out.println("enter the elements of the array:");

     // read elements of the array

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

    {

        arr[i]=ss.nextFloat();

    }

   

    // check elements re in the ascending order or not

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

    {

        if(arr[j]>arr[j+1])

        {

            flag=false;

            break;

        }

    }

     // return the result

    return flag;

}

}

Explanation:

With the help of scanner class object, read the size "m" of array.Create an array of  the given size. Pass array and integer into the function issorted(). Read the elements of the array and then check elements are in the ascending order or not.It will return "true" if elements are in the sorted order else it will return "false".

Output:

enter  size  of the array:                                                                                                                                    

5                                                                                                                                                              

enter the elements of the array:                                                                                                                              

1 2 3 4 7                                                                                                                                                      

array in the ascending sorted order  : true                                                                                                                              

enter  size  of the array:                                                  

5                                                                            

enter the elements of the array:                                              

2 4 9 3 5                                                                  

array in the ascending sorted order  : false

You might be interested in
A(n ____________ is considered a named collection of bytes having persistent or lasting storage.
kykrilka [37]
A(n) file is considered a named collection of bytes having persistent or lasting storage.
6 0
3 years ago
Your network administrator finds a virus in the network software. Fortunately,
Over [174]
B. vulnerability

It’s considered a vulnerability because the administration should have had security protections on the network.
8 0
3 years ago
A user contacted you to report that an unwanted Windows application is launched each time her computer is booted. How can you pe
nikklg [1K]

Answer:

Uninstall the application.

Explanation:

When a program or a computer application constantly launches by itself each time your system is booted, the best and most effective solution is to uninstall the application.

Uninstalling an application entails removing the application entirely from your device.

3 0
4 years ago
Given a pattern as the first argument and a string of blobs split by | show the number of times the pattern is present in each b
Ierofanga [76]

Answer:

The code is below

Explanation:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.nio.charset.StandardCharsets;

public class Main {

  /**

  *

  * Iterate through each line of input.

  *

  */

  public static void main(String[] args) throws IOException {

      InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);

      BufferedReader in = new BufferedReader(reader);

      String line;

      while ((line = in.readLine()) != null) {

          String[] splittedInput = line.split(";");

          String pattern = splittedInput[0];

          String blobs = splittedInput[1];

          Main.doSomething(pattern, blobs);

      }

  }

  public static void doSomething(String pattern, String blobs) {

      // Write your code here. Feel free to create more methods and/or classes

      int sum = 0;

      String arrblobs[] = blobs.split("\\|");

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

          int answer = 0, index = 0;

          for (;;) {

              int position = arrblobs[i].indexOf(pattern, index);

              if (position < 0)

                  break;

              answer++;

              index = position + 1;

          }

          System.out.print(answer + "|");

         

          sum = sum + answer;

      }

      System.out.println(sum);

  }

}

5 0
3 years ago
How has technology affected the way that you produce art like photographs?
kolbaska11 [484]
Many pictures and animation now can be made in technology. This makes the drawings better and more enjoyable as well as putting together an animated movie easier!
7 0
3 years ago
Other questions:
  • If you want to store the information that a user types in response to the input() function, what do you need to do? (select the
    11·1 answer
  • Which choice lists two image formats that support transparency
    6·2 answers
  • During the _____it is important to figure out how the test will be scored.
    9·1 answer
  • Which of the following protocols help IP in multicast service?
    9·2 answers
  • 2 4. What is one way to prepare for building a project budget? (1 point)​
    9·1 answer
  • Which is the best description of the difference between bound and unbound forms?
    5·2 answers
  • Suppose a class Car and its subclass Honda both have a method called speed as part of the class definition. rentalH refers to an
    5·1 answer
  • Which of the following statements is TRUE of a peer-to-peer network?
    10·1 answer
  • What are the two main types of citing information?
    12·2 answers
  • Peter has recently bought a media player and a digital camera. He wants to buy a memory card for these devices. Which memory dev
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!