📄 rationaltest.java
字号:
//program uses class Scanner
import java.util.Scanner;
public class RationalTest
{
//main method begins program execution
public static void main(String args[])
{
//create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
//create Rational objects and call the constutors
Rational u = new Rational(7 ,5 );
Rational v = new Rational(3 ,8 );
//input two numbers
System.out.printf(" the numerator and denominator of u is : ");
int a = input.nextInt();
int b = input.nextInt();
u.set(a ,b);//call method set
//input two numbers
System.out.printf(" the numerator and denominator of v is : ");
int c = input.nextInt();
int d = input.nextInt();
v.set(c ,d);//call method set
Rational t = u.add(v); //call method add and construtor
System.out.printf("u + v = ");
t.print();//call method print
Rational m = u.minus(v);//call method minus and construtor
System.out.printf("u - v = ");
m.print();//call method print
Rational n =u.multiply(v);//call method multiply and construtor
System.out.printf("u * v = ");
n.print();//call method print
Rational q =u.addition(v);//call method addition and construtor
System.out.printf("u / v = ");
q.print();//call method print
}//end main
}//end class RationalTest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -