Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab2_mob1013_ps05854_nguyendttam;
- import java.util.Scanner;
- public class Lab2_ps05854_bai1 {
- public static void main (String args [])
- {
- Scanner sc=new Scanner(System.in);
- do {
- try
- {
- System.out.println(" Xin chao den voi LAB 2 ");
- System.out.println("________________________________");
- System.out.println("| MENU |");
- System.out.println("| 1. Giai phuong trinh bac nhat|");
- System.out.println("| 2. Giai phuong trinh bac 2 |");
- System.out.println("| 3. Tinh tien dien |");
- System.out.println("| 4. Ket thuc |");
- System.out.println("________________________________");
- System.out.print("Xin moi chon chuc nang: ");
- int a=sc.nextInt();
- if(a>5){System.out.println("Chi duoc nhap so tu 1 den 4");}
- switch(a)
- {
- case 1:
- {
- Bai1();
- continue;
- }
- case 2:
- {
- Bai2();
- continue;
- }
- case 3:
- {
- Bai3();
- continue;
- }
- case 4: {
- System.out.print("Ban da thoat khoi chuong trinh");
- break;
- }
- }
- }catch (Exception ex)
- {
- System.out.print("Xin kiem tra lai");
- }
- }while(true);
- }
- public static void Bai1 () {
- try
- {
- System.out.println("---Giai phuong trinh bac 1---");
- Scanner sc=new Scanner(System.in);
- System.out.print("Nhap he so a: ");
- int a=sc.nextInt();
- System.out.print("Nhap he so b: ");
- int b=sc.nextInt();
- if(a==0)
- {
- if(b==0)
- {
- System.out.print("Phuong trinh co vo so nghiem! ");
- }
- else
- {System.out.print("Phuong trinh vo nghiem!");}
- }
- else
- {System.out.print("Phuong trinh co nghiem la: " + (-b/a));}
- }
- catch(Exception ex)
- {
- System.out.print("!!!Xin kiem tra lai he so da nhap!!!");
- }
- }
- public static void Bai2()
- {
- try
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("---Giai phuong trinh bac hai---");
- System.out.print("Nhap he so a: ");
- int a=sc.nextInt();
- System.out.print("Nhap he so b: ");
- int b=sc.nextInt();
- System.out.print("Nhap he so c: ");
- int c=sc.nextInt();
- switch(a)
- {
- case 0:
- {if(a==0)
- {
- if(b==0)
- {System.out.print("Phuong trinh co vo so nghiem! ");}
- else{System.out.print("Phuong trinh vo nghiem!");}
- }
- else{System.out.print("Phuong trinh co nghiem la: " + (-b/a));}
- }
- break;
- default:
- {
- double Delta=Math.pow(b,2)-4*a*c;
- if (Delta<0){System.out.print("Phuong trinh vo nghiem");}
- else if (Delta==0)
- {System.out.print("Phuong trinh co nghiep kep x la: " + (-b/(2*a)));}
- else
- {
- System.out.println("Phuong trinh co 2 nghiem la:");
- System.out.print("x1=" + ((-b+Math.sqrt(Delta))/(2*a)));
- System.out.print("x2=" + ((-b-Math.sqrt(Delta))/(2*a)));
- }
- break;
- }
- }
- } catch(Exception ex)
- {
- System.out.print("!!!Xin kiem tra lai he so da nhap!!!");
- }
- }
- public static void Bai3()
- {
- try
- {
- System.out.println("---Tinh tien dien---");
- Scanner sc=new Scanner(System.in);
- System.out.print("Nhap vao so dien: ");
- int soDien=sc.nextInt();
- if(soDien<50)
- {
- System.out.print("So tien phai tra la: "+soDien*1000);
- }
- else{System.out.print("So tien phai tra la: "+soDien*1200);}
- }
- catch(Exception ex)
- {
- System.out.print("!!!Xin kiem tra lai!!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement