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
xxMikexx [17]
3 years ago
13

How to find the largest number in an array java?

Computers and Technology
1 answer:
melomori [17]3 years ago
5 0

Answer:

<em>One of the ways is to sort the array, then print the last element of the sorted array.</em>

<em>In Java, you can make use of the following code</em>

import java.util.Scanner;

public class Assignment{

public static void main(String [] args)

{

int n;

Scanner input = new Scanner(System.in);

System.out.print("Array Length: ");

n = input.nextInt();

int [] myarray = new int[n];

System.out.print("Input Array: ");

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

{

           myarray[i]=input.nextInt();

}

int temp;  

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

       {  

           for (int j = i + 1; j < n; j++)  

           {  

               if (myarray[i] > myarray[j])  

               {  

                   temp = myarray[i];  

                   myarray[i] = myarray[j];  

                   myarray[j] = temp;  

               }  

           }  

       }  

           System.out.println(myarray[n - 1]);

       }

}

Explanation:

This line declares n as length of array

int n;

Scanner input = new Scanner(System.in);

This line prompts user length of array

System.out.print("Array Length: ");

This line gets the user input

n = input.nextInt();

An empty array pf length arrowed

int [] myarray = new int[n];

This line prompts user array elements

System.out.print("Input Array: ");

The following iteration gets array element from user

<em>for(int i=0;i<n;i++)</em>

<em>{</em>

<em>            myarray[i]=input.nextInt();</em>

<em>}</em>

This line declares a temporary variable temp

int temp;

<em>This iterations iterates through the elements of rge array</em>

<em>for (int i = 0; i < n; i++)   </em>

<em>        {  </em>

<em>            for (int j = i + 1; j < n; j++)   </em>

<em>            {  </em>

The following if condition checks for the larger of two variables and swap their position

<em>                if (myarray[i] > myarray[j])   </em>

<em>                {  </em>

<em>                    temp = myarray[i];  </em>

<em>                    myarray[i] = myarray[j];  </em>

<em>                    myarray[j] = temp;  </em>

<em>                }  </em>

           }  

       }  

This line prints the largest number of the array

           System.out.println(myarray[n - 1]);

You might be interested in
Which principle or element of layout design is highlighted in this event poster?
Oduvanchick [21]

The  principle or element of layout design is highlighted in an event poster in option i: The headline.

<h3>What are the elements of page layout?</h3>

The poster is known to be one that often uses a kind of hierarchy and centered text alignment as its element.

Note that it is one whose Lines of use is said to be made up of different kinds of type styles, sizes and others.

The simple elements of an advertising poster is made up of:

1. The headline.

2. The sub-head.

3. The body copy.

4. The caption.

The elements of page layout are visual hierarchy, visual flow, and others. Hence, the  principle or element of layout design is highlighted in an event poster in option i: The headline.

Learn more about layout design from

brainly.com/question/2501083

#SPJ1

6 0
2 years ago
When you adopt a certain framework or strategy for solving a series of problems, you may fail to see other, more efficient ways
Olegator [25]
I believe it is called closed mindset. Closed mindset is when you fail to see other ways to your error and don't accept help or think you can improve.
7 0
4 years ago
Dreams is Littlebigplanet 4, change my mind.
kodGreya [7K]

Answer:

It looks like a bean

Explanation:

6 0
3 years ago
A technician is tasked to implement a wireless router that will have the fastest data transfer speed at 5 GHz frequency. Which o
Basile [38]

Answer:

Option B i.e.,802.11ac is the correct option.

Explanation:

Because 802.11ac is that standard that is selected by the technician to install that router which is wireless and that router has the fastest speed of the data transfering that is 5GHz frequency. Mostly, the following standard is used in the large organizations by which the work done on time without any restriction to access the internet. So, that's why the following option is correct.

7 0
3 years ago
Enterprise information systems are also known as collaborative systems. true /false
ahrayia [7]

Enterprise information systems are also known as collaborative systems is a false statement.

<h3>What systems are also known as enterprise systems?</h3>

An enterprise system is known to be a term that is said to be also known as an enterprise resource planning (ERP) system.

Note this enterprise system is seen as a kind of a cross-functional information system that tends to give organization a form of larger scope as well as the coordination and the integration of some central business processes and aid them in the area of planning the resources of any given organization.

Note that Enterprise information systems are also known as collaborative systems is a false statement because it is an enterprise resource planning (ERP) system.

Learn more about Enterprise information systems from

brainly.com/question/14688347
#SPJ1

6 0
1 year ago
Other questions:
  • Which of the following is an Important criterion for evaluating the effctiveness of a graphic organizer
    14·2 answers
  • Monetary Policy can be either Expansionary or Contractionary. Which of the following actions classify as Expansionary Monetary P
    7·2 answers
  • Write a calculator program that keep reading operations and double numbers from user, and print the result based on the chosen o
    6·1 answer
  • Which of the following is a benefit, as well as a risk, associated with peer-to-peer networks?
    11·2 answers
  • Where can I easily find an easy app or program to use for making/editing videos?
    13·1 answer
  • The software program you need to have to read PDF file, such as the PDF files you download from your My Courses page, is
    9·2 answers
  • If a database is not maintained or if incorrect data is entered into the database, serious problems can occur. What problems cou
    15·1 answer
  • How has the Aswan High Dem had an adverse effect on human health?​
    11·1 answer
  • Which is a good guideline to follow for adding animation to a presentation?
    12·1 answer
  • A collection of wiress connecting the CPU with main memory that is used to identify particular location is called
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!