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
What are some of the visual clues a defensive driver can use to spot a impaired driver
Margaret [11]

Excessively low or high speed.

Inconsistent speed.

Swerving side to side or crossing the center line.

Failing to obey traffic signs or signals.

Getting out of the car at 40+ mph.

5 0
4 years ago
Read 2 more answers
Match each definition with the term it describes. A(n) ______ provides identification and addressing information for computers a
earnstyle [38]

Answer:

IP address, LAN, WAN

Explanation:

6 0
3 years ago
[Assembly Language]Extended Subtraction Procedure.Create a procedure named Extended_Sub --(Receives: ESI and EDI point to the tw
alex41 [277]

Answer:

Modern (i.e 386 and beyond) x86 processors have eight 32-bit general purpose registers, as depicted in Figure 1. The register names are mostly historical. For example, EAX used to be called the accumulator since it was used by a number of arithmetic operations, and ECX was known as the counter since it was used to hold a loop index. Whereas most of the registers have lost their special purposes in the modern instruction set, by convention, two are reserved for special purposes — the stack pointer (ESP) and the base pointer (EBP).

For the EAX, EBX, ECX, and EDX registers, subsections may be used. For example, the least significant 2 bytes of EAX can be treated as a 16-bit register called AX. The least significant byte of AX can be used as a single 8-bit register called AL, while the most significant byte of AX can be used as a single 8-bit register called AH. These names refer to the same physical register. When a two-byte quantity is placed into DX, the update affects the value of DH, DL, and EDX. These sub-registers are mainly hold-overs from older, 16-bit versions of the instruction set. However, they are sometimes convenient when dealing with data that are smaller than 32-bits (e.g. 1-byte ASCII characters).

When referring to registers in assembly language, the names are not case-sensitive. For example, the names EAX and eax refer to the same register.

Explanation:

5 0
3 years ago
For a data structure, such as a stack, who is responsible for throwing an exception if the stack is empty and a pop() is called:
lubasha [3.4K]

Answer:

D. End-User Programmer.

Explanation:

A stack data structure is used to holds data for programs. The first data to go into a stack is always the last to be extracted (First-in-Last-out). Data is read into the stack with the push function and retrieved with the pop function.

When the stack is empty, it means there are no data left to pop from it. If a pop function is issued at this time, the program conventionally throws an error, there is no need for the end-user to write an exception handler for it because the end-user programmer has done that already.

4 0
3 years ago
A wireless access point is most like which other network device, in that all computers send signals through it to communicate wi
scZoUnD [109]

Answer:

Hub is the correct answer for the above question.

Explanation:

  • The hub is a network hardware device which can connect more computer with the network.
  • It has a multi-point which is used to connect multiple systems with the network or internet to share the information among them.
  • When any computer which is connected through this needs to communicate with the other computers on a network then it needs to send the signals to this device first then this device sends the signal to the other device.
  • The above question ask about that device which is used to connect the computer and send the signals to communicate which is a HUB which is described above.
3 0
4 years ago
Other questions:
  • A grade of B is worth Grade points<br><br><br> A) 3.0<br> B) 80<br> C)2.0<br> D)4.0
    13·2 answers
  • SONET: is a standard for optical transmission that currently operates at Terabit per second speeds is almost identical to the IT
    7·1 answer
  • Jasper and Samantha are in a robotics competition. The guidelines state that the robots should be able to move a 10-gram weight
    9·1 answer
  • What is you full name ?​
    15·2 answers
  • C++ Proagram
    7·1 answer
  • Two technicians are discussing engine valve timing. Technician A says that the optimum valve timing is found through experimenta
    13·2 answers
  • A program virus infect​
    10·1 answer
  • (10 LC)
    5·1 answer
  • How to make classs constructer java.
    14·1 answer
  • Which of the following protocols is used by an email client to retrieve messages from an email server, giving users the option t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!