Java有关boolean类型成员方法的使用

“异常处理,打印“true”:

//filename:Bool.java
import java.util.Scanner;

/**
 * 
 * @author D3
 *
 */
class Tri {
	public double i,j,k;
	
	public Tri(double b1,double b2,double b3)
	{
		i=b1;
		j=b2;
		k=b3;
	}
	public boolean check() 
	{
		boolean x=false;
		if (i > 0 && j > 0 && k > 0) {
			x=true;
		}
		else {
			throw new IllegalArgumentException();
		}
		return x;
	}
}

public class Bool
{
	private static Scanner reader;

	public static void main(String[] args)
	{
		reader = new Scanner(System.in);
		System.out.println("请输入第一个数值: ");
		double b1=reader.nextDouble();
		System.out.println("请输入第二个数值: ");
		double b2=reader.nextDouble();
		System.out.println("请输入第三个数值: ");
		double b3=reader.nextDouble();
		Tri t=new Tri(b1,b2,b3);
		try
		{
			t.check();
		}
		catch(IllegalArgumentException e)
		{
			System.out.println("无效参数异常"+e.toString());
		}
		System.out.println(t.check());
	}
}

你可能感兴趣的:(Java有关boolean类型成员方法的使用)