Thông tin cá nhân
Xem theo danh mục
Xem theo danh mục:
Tìm kiếm: Thực đơn người xem
Bài viết cuối
Tik Tik Tak ! ^_^..........?
Bình luận mới
nguyen phuc trong
Phan So
Guest_phuc_* trong Phan So nguyen phu trong Phan So lehuy0305 trong Chuyện Net! lehuy0305 trong Chuyện Net! lehuy0305 trong Đọc đi! lehuy0305 trong Anh khờ. lehuy0305 trong Anh khờ. lehuy0305 trong Những câu nói bất hủ!!!! lehuy0305 trong Những câu nói bất hủ!!!! |
import java.util.Scanner;
// code bye dntan public class PhanSo{ private int ms; private int ts; PhanSo(int x, int y) { if (y!=0) {ts=x;ms=y;} else System.out.println("Loi nhap"); } public void rutgon(){ int x=ts,y=ms; if (x<0) x= -x; if (y<0) y= -y; if (x!=0) { while(x!=y) { if (x>y) x-=y; else y-=x; } ms=ms/x; ts=ts/x; } } public void hienthi(){ System.out.println(ts+"/"+ms); } public void cong(PhanSo p1){ this.ts=p1.ms*this.ts+p1.ts*this.ms; this.ms=this.ms*p1.ms; this.rutgon(); } public void tru(PhanSo p1){ this.ts=p1.ms*this.ts-this.ms*p1.ts; this.ms=p1.ms*this.ms; this.rutgon(); } public void nhan(PhanSo p1){ this.ts=p1.ts*this.ts; this.ms=p1.ms*this.ms; this.rutgon(); } public void chia(PhanSo p1){ this.ts=p1.ts*this.ms; this.ms=p1.ms*this.ts; this.rutgon(); } } public class Main{ public static void main(String args[]) { PhanSo p1,p2,p; int x,y; Scanner s= new Scanner(System.in); System.out.println("Chuong trinh tinh toan tren hai phan so"); p1=new PhanSo(2,4); p2=new PhanSo(3,5); System.out.println(" CAC LUA CHON "); System.out.println(" 0 : Thoat "); System.out.println(" 1 : Cong hai phan so "); System.out.println(" 2 : Tru hai phan so "); System.out.println(" 3 : Nhan hai phan so "); System.out.println(" 4 : Chia hai phan so "); int i = s.nextInt(); if (i!=0) { switch(i){ case 1: { System.out.println("Tong cua hai phan so la :"); p1.cong(p2); p1.hienthi();} break; case 2:{ System.out.println("Hieu cua hai phan so la :"); p1.tru(p2); p1.hienthi();} break; case 3:{ System.out.println("Tich cua hai phan so la :"); p1.nhan(p2); p1.hienthi();} break; case 4:{ System.out.println("Thuong cua hai phan so la :"); p1.chia(p2); p1.hienthi();} break; }//cua switch } //cua if System.out.println(" KET THUC"); }//cua main }//cua lop
|
Mạng xã hội của người Việt Nam.
VnVista I-Shine © 2005 - 2024 VnVista.com |
Bình luận
Unregistered
thank !!!!!!!!!!!
Unregistered
Unregistered