Output the maximum value from the array using Java standard output

Java exercises on a certain site. A memo of the program that inputs the integer n as the standard input, then inputs n arbitrary numerical values and outputs the maximum value from them.

import java.util.Scanner;

public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //Enter the integer n
      int num = sc.nextInt();
      int max = 0;
      int[] array = new int[num];

      //Enter an arbitrary value n times
      for(int i = 0; i < num; i++){
         array[i] = sc.nextInt();
         if(max < array[i]){
            max = array[i];
         }
      }
      System.out.println(max);
   }
}

Recommended Posts

Output the maximum value from the array using Java standard output
[Java] Color the standard output to the terminal
Try accessing the dataset from Java using JZOS
[Java] Get a random value from an array
[Java] Program example to get the maximum and minimum values from an array
Try implementing the Eratosthenes sieve using the Java standard library
[Java] How to get the maximum value of HashMap
How to output standard from an array with forEach
Using the database (SQL Server 2014) from a Java program 2018/01/04
Java standard log output sample
Using Docker from Java Gradle
Java comparison using the compareTo () method
[Java] Output multidimensional array / spreadsheet (AOJ‚Ď• spreadsheet)
How to output the value when there is an array in the array
The road from JavaScript to Java
[Java] Conversion from array to List
Sample code using Minio from Java
How to return a value from Model to Controller using the [Swift5] protocol
The value is taken out from the double hash and output by the getter.
[Java] Generate a narrowed list from multiple lists using the Stream API
Display Japanese calendar and days of the week using java8 standard class
Data processing using stream API from Java 8
Newcomer training using the Web-Basic programming using Java-
Try using the Stream API in Java
Map without using an array in java
Kick ShellScript on the server from Java
Reverse Key from Value in Java Map
Hit the Salesforce REST API from Java
Using JavaScript from Java in Rhino 2021 version
[Java] Use cryptography in the standard library
Organized memo in the head (Java --Array)
Compare the elements of an array (Java)
Connect from Java to MySQL using Eclipse
Call Java methods from Nim using jnim
Output of the book "Introduction to Java"
Try using the Emotion API from Android
Try using the Wii remote with Java
From terminal to Ruby (standard input / output)
Try adding text to an image in Scala using the Java standard library
Output the sum of each name and its contents from a multiple array
Java array
Java array
java (array)
[Java] Get and display the date 10 days later using the Time API added from Java 8.
Java array
[Java] Array
Initialize Ruby array with 0 like Java, that is, set the default value to 0
Java array
java array
[Java] Array
Access Forec.com from Java using Axis2 Enterprise WSDL
[Java] From two Lists to one array list
Using JUnit from the command line on Ubuntu
ChatWork4j for using the ChatWork API in Java
[Java] How to get and output standard input
[Java] Set the time from the browser with jsoup
Newcomer training using the Web-Basic programming / classes using Java-
Try calling the CORBA service from Spring (Java)
[Java] Convert DB code to code value using enum
[Java] Get multiple values from one return value
Display "Hello World" in the browser using Java