answersLogoWhite

0

There are two basic steps to finding the greatest number. 1) convert the input from Strings to ints (or doubles or whatever number type you are expecting), 2) find the greatest number.

/*

For this example we're going to answer the question exactly,

with no regard to expandability (for dealing with more numbers).

*/

public static void main(String[] args) {

// step 1 - convert input from Strings to ints

int a = 0, b = 0, c = 0;

// we need to wrap a try-catch block around this to

// deal with any input that cannot be converted from

// a String to an int

try {

a = Integer.parseInt(args[0]);

b = Integer.parseInt(args[1]);

c = Integer.parseInt(args[2]);

}catch(NumberFormatException ex) {

// do whatever you need to do here to manage the

// exception

}

// step 2 - find the greatest number

int max = a;

if(b > max) {

max = b;

}

if(c > max) {

max = c;

}

// at this point the value in max is the greatest of the three

// numbers passed in through the command line

}

OR ELSE YOU SHOULD TRY THE ANOTHER STYLE FOR COMMAND LINE ARGUMENT , AS IT IS GIVEN BELOW.

class Max_command

{

public static void main(String args[])

{

for(String name : args)

{

System.out.println(name);

}

int i,max=0;

for(i=0;i<=args.length;i++)

{

int a=Integer.parseInt(args[i]);

if(a>max)

{

max=a;

}

if(i==args.length-1)

{

System.out.println("Max is --> "+max);

}

}

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i &lt; 100; i+=2) { System.out.println(i); }


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.


How do you write a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method.


Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


Write Java program to find numbers from 50 to 100 which are divisible by 5?

Here's a simple Java program to find numbers from 50 to 100 that are divisible by 5: public class DivisibleByFive { public static void main(String[] args) { for (int i = 50; i &lt;= 100; i++) { if (i % 5 == 0) { System.out.println(i); } } } } This program uses a for loop to iterate through numbers from 50 to 100 and checks if each number is divisible by 5 using the modulus operator. If it is, the number is printed to the console.


Java program to find sum on even numbers from 12-45?

sum = 0; for (int i = 12; i


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How write new line program in java?

\n