Computer Science, asked by varsha6371513, 4 hours ago

write a program to input a number on command line argument and calculate maximum of them​

Answers

Answered by hareeshmahant111
14

Answer:

class Max

{       

    public static void main(String[] args)

{

    if (args.length == 0)

        {

            System.out.println("You must enter at least 1 integer. Please try again.");

            System.exit(0);

        }

    findMax(args);

 

}

 

static void findMax(String[] strValues)

{

int numMax = numbers[0];

        //int maxValue=0;

        for (int i = 0; i < strValues.length; i++)

        {

        int numbers = Integer.parseInt(strValues[i]);

        if(numbers[i] > numMax){ 

            numMax = numbers[i];

            System.out.println(numMax);

 

        {           

        }

         

        System.out.println(numMax);

        }

}

}

Answered by GouravSharmaGuru
1

Answer:

package com.gouravsharma;    // package name can be different

import java.util.Arrays;              

public class Main

{

 public static void main(String[] args)

  {  if (args.length == 0)

      {

         System.out.println("\n Gourav Atleast ek integer to enter kro.");

         System.exit(0);

       }

      else{

               Arrays.sort(args);

               System.out.println("\n Maximum number is : " + args[args.length-1]);

              }

  }

}

Explanation:

simple,  just enter the n number input values on command line argument then run this program.

This program basically convert unsorted values into sorted array , yaani sort krne ke baad jo array ka last element hoga vo hi maximum number hoga.

I hope you understand clearly.

Advise : Never stop learning and just try to solve the same problem in another way. Because a problem can be solved in many ways.

Attachments:
Similar questions