Largest Integer
Coding Problem Keys
Largest Integer
Problem Statement
An array of N integers is read from a file. The file name is stored in the variable fileName. Fill in the missing lines of code to print the largest of N integers.
Boundary Condition(s)
1 <= N <= 1000
Input File Format
      The first line contains N.
    
    
      The second line contains N integers separated by space(s).
    
    Output File Format
          The first line contains an integer.
        
    Example Input/Output 1
Input
5
21 56 23 89 64
Output
89
Example Input/Output 2
Input
6
    102 456 28 10 23 666
    Output
      666
    
Note: Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Java Language
import java.io.*; import java.util.*; public class Hello { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String fileName = scan.next();
try{
    File f=new File(fileName);
    Scanner sc=new Scanner(f);
    sc.nextLine();
    int x=0;
    String c=sc.nextLine();
    String [] s=c.split(" ");
    for(String ch:s){
        int t=Integer.parseInt(ch);
        if(t>x) x=t;
    }
System.out.println(x);
}
catch(Exception e){
    System.out.println("Error");
}
// Published By PKJCODERS
    } }
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments