How to find the largest number in an array java?

Answers

Answer 1

Answer:

One of the ways is to sort the array, then print the last element of the sorted array.

In Java, you can make use of the following code

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

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

{

           myarray[i]=input.nextInt();

}

This line declares a temporary variable temp

int temp;

This iterations iterates through the elements of rge array

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

       {  

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

           {  

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

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

               {  

                   temp = myarray[i];  

                   myarray[i] = myarray[j];  

                   myarray[j] = temp;  

               }  

           }  

       }  

This line prints the largest number of the array

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


Related Questions

Mateo has received a Word document from a customer that contains private information and is secured with a password. However, when Mateo tries to open the
document in his browser, he gets an error message. How might he fix this problem?
a Use a secure website that starts with HTTPS
b. Open the document in the Word app installed on his computer
c Save the document in the cloud
d Ensure there's a lock icon in the browser

Answers

Answer:

open it in a different app

Explanation:

Which of the following is considered a basic task in the context of computer operations? a. Connecting to the Internet b. Natural language processing c. Word processing d. Logical operations

Answers

Answer:

The answer is "Option d".

Explanation:

The performing function into the computer is made up of three basic functions, that are: logical, arithmetical, and memory processes, in which the logical process or function is a particular symbol or expression, that links two or more knowledge sentences, and the incorrect choices can be explained  as follows:

In Option a, It is wrong because it can't provide the basic tasks.In Option b, It an algorithm, that's why it is incorrect.In Option c, It is a software, which is used to provide editing on text, that's why it is incorrect.

A task which is considered as a basic task in the context of computer operations is: D. Logical operations.

What is a computer?

A computer can be defined as an electronic device that is designed and developed to receive data in its raw form as an input and processes these data into an output (information) that could be used by an end user.

In Computer technology, the basic task in the context of computer operations are broadly classified into three (3) categories and these include the following:

Arithmetical operations.Memory processes.Logical operations.

Read more on computer here: brainly.com/question/959479

Students enrolled in a digital classroom participate in discussions and take field trips with classmates. watch instructional videos and turn in assignments online. take notes online but take tests in front of a teacher at school. listen to lectures online but make presentations at school.

Answers

Answer:b

Explanation:gszrxewzgdtxherhzre

Students enrolled in a digital classroom participate in discussions and take field trips with classmates turn in assignments online.

What is assignment?

Assignment is defined as a duty that you have been tasked with by a higher authority. The verb "to assign" is used to assign duties or jobs to other people, while the word "assignment" is essentially the verb's noun form. The opportunity to learn, practice, and demonstrate mastery of the learning objectives is provided to the students. It gives the teacher proof that the students have met their objectives.

Keep an eye on how the students are using the technology. Examine how students are collaborating and what websites or apps they are using by moving around the classroom. Give pupils detailed instructions on the school's policies and practices for using technology in the classroom.

Thus, students enrolled in a digital classroom participate in discussions and take field trips with classmates turn in assignments online.

To learn more about assignment, refer to the link below:

https://brainly.com/question/29585963

#SPJ2

2.2-2 Consider sorting numbers stored in array by first finding the smallest element n A of and exchanging it with the element in . Then find the second smallest A AOE1 element of A, and exchange it with . Continue in this manner for the firs AOE2 1 elements of A. Write pseudocode for this algorithm, which is known as selection sort. What loop invariant does this algorithm maintain? Why does it need to run for only the firs elements, rather than for all elements? Give the best-case n 1 n and worst-case running times of selection sort in ‚-notation.

Answers

Answer:

Follows are the explanation of the choices:

Explanation:

Following are the Pseudocode for selection sort:                      

for j = 0 to k-1 do:

      SS = i

      For l = i + 1 to k-1 do:

        If X(l) < X(SS)

          SS= l

        End-If

      End-For

      T = X(j)

      X(j) = X(SS)

      X(SS) = T

    End-For

Following are the description of Loop invariants:

The subarray  A[1..j−1] includes the lowest of the j−1 components, ordered into a non-decreasing order, only at beginning of the iteration of its outer for loop.  

A[min] is the least amount in subarray A[j.. l−1] only at beginning of the each loop-inner iterations.                      

Following are the explanation for third question:

Throughout the final step, two elements were left to evaluate their algorithm. Its smaller in A[k-1] would be placed as well as the larger in A[k]. One last is the large and medium component of its sequence because most and the last two components an outer loop invariant has been filtered by the previous version. When we do this n times, its end is a repetitive, one element-sorting phase.

Following is the description of choosing best-case and worst-case in run- time:

The body the if has never been activated whenever the best case time is the list is resolved. This number of transactions are especially in comparison also as a procedure, that will be (n-1)(((n+2)/2)+4).    

A structure iterator at every point in the worst case that array is reversed, that doubles its sequence of iterations in the inner loop, that is:(n−1)(n+6) Since both of them take timeΘ(n2).

What are three purposes of the Media Creation Tool application?

Answers

Answer:

The first purpose fo the Media Creation Tool Application is:

to enable the creation or building the Windows 10 installation media. The Windows 10 installation media is not Windows 10It can also be used to repair an existing installationIt is used to make a bootable USB memory stick for use in the installation of Windows 10

Cheers!

The three purposes of the Media Creation Tool application are:

To stored data.To download a Windows 10 install file.To reinstall Windows 10.

What is the purpose of the media creation tool?

The Media Creation Tool is known to be an application that helps a person to be able to download a Windows 10 install file.

Here the person can get this file and put it into a flash drive or a DVD and then one can save it  so that one can be able to still use it to reinstall the Windows 10. It is known to act as a kind of backup option in case your system has malfunctions.

Learn more about Media Creation from

https://brainly.com/question/1114645

Compare WiFi hotspot and cyber cafe ??? I will give you slot of points HELP!!!

Answers

Explanation:

A WiFi hotspot is a wireless internet connection that allows a computer, smartphone, or other internet-enabled devices to connect to internet access points.

While a Cybercafe (internet cafe) refers to any business space which allows people to access the internet usually within its premises after paying for connection access. Unlike Wifi hotspot, a cybercafe in most cases provides computers to their customers.

Answer:

ExplanatiA WiFi hotspot is a wireless internet connection that allows a computer, smartphone, or other internet-enabled devices to connect to internet access points.

While a Cybercafe (internet cafe) refers to any business space which allows people to access the internet usually within its premises after paying for connection access. Unlike Wifi hotspot, a cybercafe in most cases provides computers to their customers.on:

A(n) _____ is a common output device for hard copy.
a. laser printer
b. optical character reader
c. plasma display
d. compact disc

Answers

The answer is d it is d it is d I think I think, I’m not sure though

Anna wants to keep information secure from offenders. Which software should she install on her computer to ensure Internet safety?
O A database software
OB
presentation software
OC. anti-virus software
OD
graphics software

Answers

Anna wants to keep information secure from offenders. Which software should she install on her computer to ensure Internet safety?

O A database software

OB

presentation software

OC. anti-virus software

OD

graphics software

Answer: OC

You are configuring two PCs for your network, PC-A is given an IP address of 192.168.1.18 and PC-B is given an IP address of 192.168.1.33. Both PCs receivces a subnet mask of 255.255.255.240A) what is network address of PC-A?B) what is network address of PC-B?C) will these PCs be able to communicate directly wiyh each other?D) what is the highest address that can be given to PC-B that allows it to be on the same network as PC-A ?

Answers

Answer:

Explanation:

a) 192.168.1.16

b) 192.168.1.32

c) No

d) 192.168.1.30

Answer:

It’s somethint

Explanation:

what is the purpose of social networking sites

Answers

Explanation:

social networking sites allow users to share ideas, digital photos and videos, posts, and to inform others about online or real world activities and events with people in their network.

Check
Which tasks can a user accomplish by using the Find and Replace feature of Word? Check all that apply.
changing the size of the page
changing the case of a word
changing the spelling of a word
changing the margins of the page
changing a word to another word

Answers

Answer:

B,C,E :)

Explanation:

Answer:

B, C, E is the correct answer

Explanation:

edge2021

Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total.For example, if the user enters 10 for subtotal and 15% for gratuity rate,the program displays $1.5 as gratuity and $11.5 as total.Sample RunEnter the subtotal and a gratuity rate: 10 15The gratuity is $1.5 and total is $11.5Class Name: Exercise02_05

Answers

Answer:

Using Javascript,

function calTotal( subtotal, gratuity){

  gratuityValue = subtotal * (gratuity/100)

  total = subtotal + gratuityValue

  console.log( "gratuity: ", gratuityValue , "\nTotal: ", total)

}

Explanation:

The javascript function above is able to collect two parameters subtotal and gratuity rate in percentage and calculate the total and gratuity value, and displays it on the console.

Changing the appearance of the text in your document, is to _________________ it.

Answers

Answer:

Format

Explanation:

I dont really know what the explanation would be but hope this helps.

Amanda a recently moved into a new home. Everyone has their own tablet, and wants to connect to the same network, no matter where they are in the house. Which type of network is best for Amanda and her family?nd her family recently moved into a new home. Everyone has their own tablet, and wants to connect to the same network, no matter where they are in the house. Which type of network is best for Amanda and her family?

Answers

Answer:

wifi is the best network for all, As it gets in all corners of the house.

______was developed as an interim management protocol with OSI as the ultimate network management protocol.

Answers

Answer:

Simple Network Management Protocol

Explanation:

Simple Network Management Protocol otherwise referred to as SNMP is a form of computer protocol that is mainly used in obtaining and regulating information relating to connected gadgets. It is practically based on the internet and was originally planned as an interim protocol.

Hence, it can be concluded that the Simple Network Management Protocol was developed as an interim management protocol with OSI as the ultimate network management protocol.

4 types of system software

Answers

Operating systems.
Device drivers.
Middleware.
Utility software.

4 types of system software: Operating Systems (OS), Device Drivers, Utilities, and Language Translators.

1. Operating Systems (OS): Operating systems are the core system software that manages computer hardware and software resources.

They provide an interface for users to interact with the computer and facilitate the execution of applications.

2. Device Drivers: Device drivers are software components that enable communication between the operating system and hardware devices like printers, graphics cards, and network adapters.

3. Utilities: System utilities perform various maintenance tasks, such as disk defragmentation, file management, backup, and system optimization.

4. Language Translators: These tools, including compilers and interpreters, translate high-level programming languages into machine code that the computer can execute.

Know more about system software:

https://brainly.com/question/30166062

#SPJ5

In real-world environments, once the domains that are affected by the risks are identified, subsequent next steps would include:______.

Answers

Answer:

Explanation:

In real-world environments, once the domains that are affected by the risks are identified, subsequent next steps would include selecting, implementing, and testing controls to minimize or eliminate those risks.

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After statement cin >> one >> two; executes________ a) one = 10.5, two = 10.5 b) one = 11, two = 31 c) one = 30.6, two = 30.6 d) one = 10.5, two = 30.6

Answers

Answer:

The answer is "Option d"

Explanation:

In the given C++ program code, It is defined, that two double type variable "one and two" is defined, that holds the two double value that is "10.5 and 30.6".

In this code, it uses the "cin" method for input values from the user ends, when we execute this code, it provides the console screen, that inputs the double type value from the user side, and other given choices were wrong because it holds different values.

How Oracle 12c advances the security discussion?

Answers

Answer: The oracle 12 c advances are given below.

Explanation:

The oracle 12 c provides the ability to tag the data with the label of data. It provides the classification to the data. This allows to check which data is sensitive and also allows the combination of sensitive data to be combined with the same table as the bigger data without compromising the security of the database.

Expain the application areas of ICT in education sector and E-commerce​

Answers

Explanation:

Nowadays almost all the school and college use computers in classrooms and labs to teach students.A teacher can teach effectively using computer-based presentations.Students can study different subjects and complete their assignment by using different software in computer.The Computer Based Training(CBT) and Web Based Training(WBT) are aid to teach the student in the classroom.

E-commerce is a financial business transaction conducted electronically between business partners over the internet.Business transactions can occur very quickly and globally.The people can buy,sell and exchange the products or services using internet.Todays many computer can also access the Internet through wireless technologies.

Screenwriters would be least involved in planning which type of film?

Answers

This question is incomplete; here is the complete question:

Screenwriters would be least involved in planning which type of film?

A. Mystery

B. Historical fiction

C. Documentary

D. Adventure

The answer to this question is C. Documentary

Explanation:

The role of screenwriters is to create different elements in a film including the dialogues between the characters, the actions or events that occur, and even the general story that is told. Due to this, screenwriters play an essential role in fiction based films which include genres such as historical fiction, adventure, science fiction, etc.

However, screenwriters are less involved in genres such as documentaries because the purpose of documentaries is to show reality, this implies there are no fictional characters or one fictional story playwriters should create.

Answer:

b: documentary

Explanation:

edg2021

Which of the following situations would notqualify for the fair use exception to United States copyright law?A) Google posts thumbnail images of books in the Google Book Search Project.B) A student copies a photograph of his favorite band from a Web site created by the band's record label andplaces it on the student's personal Web site. C) A professor clips a newspaper article just before class and distributes copies of it to his class.D) A journalist quotes a paragraph from a book in a review of the book.

Answers

Answer:

C. A student copies a photograph of his favorite band from a Web site created by the band's record label and places it on the student's personal Web site.

Explanation:

Because this is deemed an offence as the student never got a formal copyingpermit

When you're formatting in excel 2013 there are basically three levels of formatting, put the
three levels in order of top to bottom levels​

Answers

Answer:

The answer is "themes, styles, and direct formatting".

Explanation:

The selection of regular colors, font color, or type effects is also known as the Themes. There are many built-on Excel categories accessible mostly on page layout menu: an overview of its impact on the workbook could be accessed via a topic. You may find which various fonts will affect the design of your workbook.  The style of a column is indeed a defined collection of layout tools like font and font color, numbers, cell borders, and cell shading. The range of cell styles incorporated, that can be added or modified. It could also alter or double a cell template to build your customizable cell model. To use a customized format it includes the font, color, borders, etc. It is the direct formatting for the document at a certain time and anywhere. It selects the cell and starts changing the font from the font drop list to modify the font of its current document.

Where do today's computers store almost all motherboard configuration data?A) BIOS ROMB) CMOS RAMC) DIMM RAMD) Solid State Disk

Answers

Answer:

In the CMOS RAM

Explanation:

It's the only answer that is available. New computer's store the data in TPM (Trusted Platform Module) is an international standard for a secure cryptoprocessor, a dedicated microcontroller designed to secure hardware through integrated cryptographic keys.

Today's computers store almost all motherboard configuration data in CMOS RAM (Complementary Metal-Oxide-Semiconductor Random Access Memory). (Option B)

How  is this so?

CMOS RAM is a type of non-volatile memory that retains data even when the computer is powered off. It is typically powered by a small battery on the motherboard.

The configuration data stored in CMOS RAM includes settings such as system date and time, boot order, hardware settings, and other BIOS (Basic Input/Output System) configurations.

Thus the correct answer is Option B - Complementary Metal-Oxide-Semiconductor Random Access Memory

Learn more about motherboard  at:

https://brainly.com/question/12795887

#SPJ6

Which guidelines should be used to make formatting tasks more efficient?

Answers

Answer:

Use pasted text only; this does not keep the original formatting.

Explanation:

Which of the following is usually used to connect a monitor to a computer?
O DVI cable
O USB cable
O Ethernet cable
O SATA cable

Answers

Answer:

Ethernet cable

Explanation:

this is because you usually use a ethernet cable at schools , offices and even at home so ya tell me if im wrong

The DVI cable is usually used to connect a monitor to a computer option (A) DVI cable is correct.

What is a computer?

A computer is a digital electronic appliance that may be programmed to automatically perform a series of logical or mathematical operations. Programs are generic sequences of operations that can be carried out by modern computers.

The Digital Display Working Group created the digital video interface known as DVI (Digital Visual Interface) (DDWG).

It is frequently found on computers, LCD monitors, projectors, and other digital display devices.

It supports both digital and analog video signals via a single DVI connection.

Thus, the DVI cable is usually used to connect a monitor to a computer option (A) DVI cable is correct.

Learn more about computers here:

brainly.com/question/21080395

#SPJ2

SQL a. has become the de facto standard database language b. can be used to define database systems c. both a. and b. d. none of the above

Answers

Answer:

a.)has become the de facto standard database language

Explanation:

SQL known as Structure Query Language can be described as domain specific language that is Been used in execution of tasks son database. Those task could be updating of data.

Database admistraion.

Microsoft SQL server is one of the example of database system that uses SQL.

It should be noted that SQL has become the de facto standard database language

What is the full form of computer ​

Answers

Answer:

Computer is not an acronym, it is a word derived from a word "compute" which means to calculate. Some people say that COMPUTER stands for Common Operating Machine Purposely Used for Technological and Educational Research.

what connects data center to your device?

Answers

My answer to the question is ISP(Internet Service Provider).

#TODO: Define a data structure to keep track of which links are part of / not part of the spanning tree.

Answers

Answer:

A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected.. By this definition, we can draw a conclusion that every connected and undirected Graph G has at least one spanning tree.

Other Questions
What is Average rainfall in the desert? Since cos(x) is the derivative of sin(x), then integral 16 sin^2(x) cos(x) dx can be done by substituting u = sin (x) sin (x) and du = cos (x) cos (x)^dx. With the substitution u = sin(x), we get integral 16 sin^2 (x) cos(x) dx = 16 integral u^2 du. which integrates to + C. Substituting back in to get the answer in terms of sin(x), we have integral 16 sin^2 (x) cos (x) dx = + C. Is there a known infinite product for e? What I mean is, its similar to an infinite series. HELP- To promote health and safety at work, Congress passed a law known as the Occupational Safety and Health Act in 1970. This law requires employers to adhere to certain health and safety standards for ensuring employee well-being and safety. Employers need to follow the health and safety guidelines that the Occupational Safety and Health Administration (OSHA) prescribes. Research online and write about the safety guidelines that employers should follow as per OSHA. Also, describe how you manage your personal safety and health. List your short-, medium-, and long-term physical-fitness goals as well. Help needed ASAP will give BRAINLIEST 29. (407)Got gbvttvgbybtvrcrcgbbgbgbtvfvtvybgbtvtcvfbghnvgvffvhbjngbvfvfgb HELP! WILL GIVE BRAINLIEST IF YOUR ANSWER IS RIGHT Maria lives in Mexico. Both of her parents are Mexican. Maria is a Mexican citizen. She was born in an American hospital when her parents were on a short vacation in San Diego, California. Was Maria an American citizen at birth? Explain your answer. A atom has 20 electrons, 21 neutrons, and 20 protons. What is the atomic mass of the atom? write an equation for each description : two thirds a number plus 4 is 7 What violent episode does John Smith go through? What is John Smith attitude towards violence? write a quadratic equations given the roots 5/2 and 9 What is the main function of chloroplasts? Choose 1 answer:(Choice A) A To store food, water, and waste (Choice B) B To package and sort proteins (Choice C) C To convert sunlight into usable sugars (Choice D) D To produce ATP for the cell A family structure with either two or more adult generations, or with both grandparents and grandchildren living under one roof is known as Helping others with their problems shows your family that you care. Para executar um servio, o trabalhador apoiou na laje de sua casa a escada de 4,3 m de comprimento como mostra o esquema abaixo: A base da escada, apoiada sobre um piso horizontal est afastada 1,8 m da parede. Qual a altura aproximada da construo? PLEASE HELP!!! I HAVE 10 minutes LEFT!! as readers you must learn to consider critically the validity of advertisers claims and to know how to what is the use of a divider Marguerite drove 100 miles in 2.4 hours. If Sam drove for 3 hours at the same average rate as Marguerite, how many miles did he drive? advantages and disadvantages of performance enhancing drugs and athletes