Posted in : Java Beginners

View Answers

August 11, 2008 at 1:49 PM

import java.io.*;

public class max_min1

{

public static void main(String a[]) throws IOException

{

int max,min;

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

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

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

{

if(Integer.parseInt(a[i])<min)

min=Integer.parseInt(a[i]);

if(Integer.parseInt(a[i])>max)

max=Integer.parseInt(a[i]);

}

System.out.println("MAX: "+max+" MIN: "+min);

}

}

public class max_min1

{

public static void main(String a[]) throws IOException

{

int max,min;

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

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

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

{

if(Integer.parseInt(a[i])<min)

min=Integer.parseInt(a[i]);

if(Integer.parseInt(a[i])>max)

max=Integer.parseInt(a[i]);

}

System.out.println("MAX: "+max+" MIN: "+min);

}

}

August 11, 2008 at 1:53 PM

here...a is an array....the data type is String....

This pgm takes values as command line...

the first value is assignd to both min and max variables....

now, in a loop...till the end of the array...check each values against the max and min variables....then assign accordding to the comparison...

we have to convert this array values into integer.

This pgm takes values as command line...

the first value is assignd to both min and max variables....

now, in a loop...till the end of the array...check each values against the max and min variables....then assign accordding to the comparison...

we have to convert this array values into integer.

August 11, 2008 at 2:08 PM

Hi friend,

Import the java input output packages

import java.io.*;

public class MaxMinFun {

public static void main(String[] args) throws IOException

{

// Max Number to be inputted

System.out.println("Enter Number to be input: ");

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String str = in.readLine();

// Enter the Number and store it in array;

int arlen = Integer.parseInt(str.toString());

int[] arr = new int[arlen];

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

{

str = in.readLine();

arr[i] = Integer.parseInt(str.toString());

}

//code to calculate the maximum number :

int arrayMax[]= arr;

int max = arrayMax[0];

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

{

if(max<arrayMax[i])

{

max = arrayMax[i];

}

}

System.out.println("max = " + max);

//code to calculate the minimum number :

int arrayMin[]= arr;

int min=arrayMin[0];

for (int i=1; i<arrayMin.length; i++)

{

if(min>arrayMin[i])

{

min = arrayMin[i];

}

}

System.out.println("min = " + min);

}

}

Thanks

Import the java input output packages

import java.io.*;

public class MaxMinFun {

public static void main(String[] args) throws IOException

{

// Max Number to be inputted

System.out.println("Enter Number to be input: ");

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String str = in.readLine();

// Enter the Number and store it in array;

int arlen = Integer.parseInt(str.toString());

int[] arr = new int[arlen];

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

{

str = in.readLine();

arr[i] = Integer.parseInt(str.toString());

}

//code to calculate the maximum number :

int arrayMax[]= arr;

int max = arrayMax[0];

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

{

if(max<arrayMax[i])

{

max = arrayMax[i];

}

}

System.out.println("max = " + max);

//code to calculate the minimum number :

int arrayMin[]= arr;

int min=arrayMin[0];

for (int i=1; i<arrayMin.length; i++)

{

if(min>arrayMin[i])

{

min = arrayMin[i];

}

}

System.out.println("min = " + min);

}

}

Thanks

August 11, 2008 at 2:08 PM

is it the answer u r looking for....

Then if u got a better one, plz inform me also...

thanks and reg..

prashu..

prashobvee@gmail.com

Then if u got a better one, plz inform me also...

thanks and reg..

prashu..

prashobvee@gmail.com

Related Tutorials/Questions & Answers: