English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

public class solve
{
public static void main( String args[] )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

int x; // first number input by user
int y; // second number input by user
int z; // third number input by user
int a; // fourth number input by user
int result; // output of product
int result1;
int min;
int max;

System.out.print( "Enter first integer: " ); // prompt for input
x = input.nextInt(); // read first integer

System.out.print( "Enter second integer: " ); // prompt for input
y = input.nextInt(); // read second integer

System.out.print( "Enter third integer: " ); // prompt for input
z = input.nextInt(); // read third integer

System.out.print ("Enter fourth integer: " ); // prompt for input
a = input.nextInt (); // read fourth integer

result = x + y + z + a; // calculate product of numbers

result1 = x * y * z * a;


min = x;
if (y < x)
min = y;
if (z < y)
min = z;
if (a < z);
min = a;



max = x;
if (y > x)
max = y;
if (z > y)
max = z;
if (a > z);
max = a;





System.out.printf( "Sum is %d\n", result );
System.out.printf( "Product is %d\n", result1 );
System.out.printf( "Minimum is: " , min );
System.out.printf( "Maximum is: " , max );

2006-10-12 18:10:49 · 3 answers · asked by azhi_saleem 1 in Computers & Internet Programming & Design

3 answers

The problem in your program is in your comparison portions.

min = x;
if (y < x) // this should be if (y < min) & similarly all conditions
min = y;
if (z < y)
min = z;
if (a < z);
min = a;



max = x;
if (y > x) //This should be if(y>max) & similarly for other conditions.
max = y;
if (z > y)
max = z;
if (a > z);
max = a;

If you do the above instructed changes, you will get the program working properly.

2006-10-14 01:36:28 · answer #1 · answered by Pandian 3 · 0 0

can you post some input and output examples?.. the only thing i see in the code is you shouldn't have a semicolon after if (a > z); in both cases. But that's a small case, if your having the errors across the board.

As a suggestion you may also want to look at java.util.Math, it includes min and max functions.

2006-10-12 19:12:37 · answer #2 · answered by Brady 3 · 0 0

Dear,

Go to www.sun.com,sun microsystems the Java Platform inorder to gain the latest version of java.


In case of further issues regarding computers & internet dont forget to contact via...
Yahoo! Groups
vijaysomanath - Customer Support Knowledge Database,
http://tech.groups.yahoo.com/group/vijaysomanath

¤ Regards, vijaysomanath
¤ http://www.spaces.msn.com/vijaysomanath
¤ Copyright © 1999-2006 vijaysomanath. All rights reserved.

2006-10-12 18:12:42 · answer #3 · answered by Anonymous · 0 1

fedest.com, questions and answers