Java Programming Home Page: Archive: Message #25

Date: Feb 09 2000 15:38:42 EST
From: "Java Programming" <javaProgramming-owner@listbot.com>
Subject: using the ? operator

Hi All,
in the following example, I show how to use
the ? operator.

Do you know how to write a program that takes the min
or max of three number? how about 30 numbers?

Regards, -DL

public class ConditionalDemo {
	public static void main(String args[]) {	
		ConditionalDemo cd	
			= new ConditionalDemo();
		cd.run(10,20);
		cd.run(20,10);
	}
	
	public void run(int x, int y) {
		System.out.println("x,y="
			+x+','+y
			+" max="+max(x,y)
			+" min="+min(x,y));
	}

	public int min(int x, int y) {
		return x < y ? x : y;
	}
	public int max(int x, int y) {
		return x > y ? x : y;
	}
}