Trang 4 của 4 Đầu tiênĐầu tiên ... 234
Kết quả 31 đến 38 của 38
  1. #31
    Ngày tham gia
    Apr 2015
    Bài viết
    0
    Trích dẫn Gửi bởi hatb
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>btvn - try/catch (move your mouse to reveal the content)</noscript>

    btvn - try/catch (open)
    btvn - try/catch (close)

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>


    Mã nguồn PHP:
    [color=#000000]
    package baitapvenha[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];[/color][color=#ff8000]/*** làm lại bài giải phương trình ax + b = 0 . lập trình hướng đối tượng. các hệ* số nhập vào từ bàn phím. sử dụng try - catch để bẫy các lỗi khi nhập sai kiểu* dữ liệu, ví dụ nhập số lại nhập chữ. bẫy lỗi chia cho 0.*/[/color][color=#007700]public class [/color][color=#0000bb]buoi22_trycatch [/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) { [/color][color=#0000bb]phuongtrinh pt [/color][color=#007700]= new [/color][color=#0000bb]phuongtrinh[/color][color=#007700](); [/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]nhapheso[/color][color=#007700](); [/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]giaipt[/color][color=#007700](); }} class [/color][color=#0000bb]phuongtrinh [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700], [/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void nhapheso[/color][color=#007700]() { [/color][color=#0000bb]scanner sc [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap he so cho phuong trinh:"[/color][color=#007700]); try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"a = "[/color][color=#007700]); [/color][color=#0000bb]seta[/color][color=#007700]( [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"b = "[/color][color=#007700]); [/color][color=#0000bb]setb[/color][color=#007700]([/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: "[/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } } public [/color][color=#0000bb]void giaipt[/color][color=#007700](){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"phuong trinh co nghiem: "[/color][color=#007700]); try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x = "[/color][color=#007700]+(float)(-[/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700])); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: "[/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); [/color][color=#ff8000]// todo: handle exception [/color][color=#007700]} } public [/color][color=#0000bb]float geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]void seta[/color][color=#007700]([/color][color=#0000bb]int a[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]float getb[/color][color=#007700]() { return [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void setb[/color][color=#007700]([/color][color=#0000bb]int b[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]; }}[/color] 
    </blockquote></div>
    </div>
    </div>

    Trích dẫn Gửi bởi hatb
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>btvn - try/catch (move your mouse to reveal the content)</noscript>

    btvn - try/catch (open)
    btvn - try/catch (close)

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>


    Mã nguồn PHP:
    [color=#000000]
    package baitapvenha[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];[/color][color=#ff8000]/*** làm lại bài giải phương trình ax + b = 0 . lập trình hướng đối tượng. các hệ* số nhập vào từ bàn phím. sử dụng try - catch để bẫy các lỗi khi nhập sai kiểu* dữ liệu, ví dụ nhập số lại nhập chữ. bẫy lỗi chia cho 0.*/[/color][color=#007700]public class [/color][color=#0000bb]buoi22_trycatch [/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) { [/color][color=#0000bb]phuongtrinh pt [/color][color=#007700]= new [/color][color=#0000bb]phuongtrinh[/color][color=#007700](); [/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]nhapheso[/color][color=#007700](); [/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]giaipt[/color][color=#007700](); }} class [/color][color=#0000bb]phuongtrinh [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700], [/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void nhapheso[/color][color=#007700]() { [/color][color=#0000bb]scanner sc [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap he so cho phuong trinh:"[/color][color=#007700]); try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"a = "[/color][color=#007700]); [/color][color=#0000bb]seta[/color][color=#007700]( [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"b = "[/color][color=#007700]); [/color][color=#0000bb]setb[/color][color=#007700]([/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: "[/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } } public [/color][color=#0000bb]void giaipt[/color][color=#007700](){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"phuong trinh co nghiem: "[/color][color=#007700]); try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x = "[/color][color=#007700]+(float)(-[/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700])); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: "[/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); [/color][color=#ff8000]// todo: handle exception [/color][color=#007700]} } public [/color][color=#0000bb]float geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]void seta[/color][color=#007700]([/color][color=#0000bb]int a[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]float getb[/color][color=#007700]() { return [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void setb[/color][color=#007700]([/color][color=#0000bb]int b[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]; }}[/color] 
    </blockquote></div>
    </div>
    </div>
    mình thấy bài này ổn nhất so với đề bài tiasangmoi92
    đưa ra đúng ko mọi người

  2. #32
    Ngày tham gia
    Mar 2015
    Bài viết
    0
    sao mình gọi phương thức xuất cố tình cho a ==0 để cho lỗi mà chương trình ko chạy vào catch vậy mọi người, với ở phương thức nhập nếu mình muốn người dùng nếu nhập hệ số a là chữ thì nó sẽ cho người dùng nhập lại hệ số a là số thì phải làm ntn . thank all anh em



    Mã nguồn PHP:
    [color=#000000]
    [/color][color=#007700]class [/color][color=#0000bb]phuongtrinh[/color][color=#007700]{private [/color][color=#0000bb]float a[/color][color=#007700];private [/color][color=#0000bb]float b[/color][color=#007700]; public [/color][color=#0000bb]float geta[/color][color=#007700]() {return [/color][color=#0000bb]a[/color][color=#007700];}public [/color][color=#0000bb]void seta[/color][color=#007700]([/color][color=#0000bb]float a[/color][color=#007700]) {[/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700];}public [/color][color=#0000bb]float getb[/color][color=#007700]() {return [/color][color=#0000bb]b[/color][color=#007700];}public [/color][color=#0000bb]void setb[/color][color=#007700]([/color][color=#0000bb]float b[/color][color=#007700]) {[/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700];} public [/color][color=#0000bb]void nhap[/color][color=#007700](){[/color][color=#0000bb]scanner nhapdulieu [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); try {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap he so a :"[/color][color=#007700]);[/color][color=#0000bb]seta[/color][color=#007700]([/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"loi nhap chu "[/color][color=#007700]);[/color][color=#ff8000]// todo: handle exception[/color][color=#007700]} try {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap he so b :"[/color][color=#007700]);[/color][color=#0000bb]setb[/color][color=#007700]([/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) {[/color][color=#ff8000]// todo: handle exception[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"loi nhap chu "[/color][color=#007700]);} } public [/color][color=#0000bb]void xuat [/color][color=#007700](){try {[/color][color=#0000bb]float a1 [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700];[/color][color=#0000bb]float b1 [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700];[/color][color=#0000bb]float x [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nghiem cua phuong trinh la x = "[/color][color=#007700]+(-[/color][color=#0000bb]x[/color][color=#007700]));} catch ([/color][color=#0000bb]exception e[/color][color=#007700]) {[/color][color=#ff8000]// todo: handle exception[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"loi b = 0"[/color][color=#007700]);} } public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string args [/color][color=#007700][]){[/color][color=#0000bb]phuongtrinh pt [/color][color=#007700]= new [/color][color=#0000bb]phuongtrinh[/color][color=#007700]();[/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]nhap[/color][color=#007700]();[/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]xuat[/color][color=#007700]();} [/color] 

  3. #33
    Ngày tham gia
    Jul 2015
    Bài viết
    0
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>



    Trích dẫn Gửi bởi tuanleedragon
    sao mình gọi phương thức xuất cố tình cho a ==0 để cho lỗi mà chương trình ko chạy vào catch vậy mọi người, với ở phương thức nhập nếu mình muốn người dùng nếu nhập hệ số a là chữ thì nó sẽ cho người dùng nhập lại hệ số a là số thì phải làm ntn . thank all anh em
    </blockquote></div>
    </div>
    </div>


    Trích dẫn Gửi bởi tuanleedragon
    @tuanleedragon: cái lỗi mà bạn nói là cố tình nhập a thì nó k ra ấy mình cũng đã bị vì do bạn dùng biền float nên có thể do hàm hỗ trợ của java nó đưa ra là -indentify gì gì đó đúng k ??? mình cũng k rõ nên mình quyết định là chuyển sang kiểu int thì lại catch được lỗi mình cũng k hiểu sao lại thế

  4. #34
    Ngày tham gia
    Sep 2014
    Bài viết
    0

    Mã nguồn PHP:
    [color=#000000]
    package lesson[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]inputmismatchexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700]; [/color][color=#ff8000]/** * * @author legendtk84 */[/color][color=#007700]public class [/color][color=#0000bb]lesson22 [/color][color=#007700]{ public static [/color][color=#0000bb]void main [/color][color=#007700]([/color][color=#0000bb]string [/color][color=#007700][][/color][color=#0000bb]args[/color][color=#007700]){ [/color][color=#0000bb]giaiphuongtrinh pt [/color][color=#007700]= new [/color][color=#0000bb]giaiphuongtrinh[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"ax+b=0"[/color][color=#007700]); [/color][color=#0000bb]pt[/color][color=#007700].[/color][color=#0000bb]en[/color][color=#007700](); }}class [/color][color=#0000bb]giaiphuongtrinh [/color][color=#007700]{ [/color][color=#0000bb]scanner scan1 [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); public [/color][color=#0000bb]int a[/color][color=#007700],[/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void en[/color][color=#007700](){ try{ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap a: "[/color][color=#007700]); [/color][color=#0000bb]a[/color][color=#007700]=[/color][color=#0000bb]scan1[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); }catch([/color][color=#0000bb]inputmismatchexception e1[/color][color=#007700]){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"co loi gi do: a phai la so nguyen "[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]e1[/color][color=#007700].[/color][color=#0000bb]tostring[/color][color=#007700]()); } try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap b: "[/color][color=#007700]); [/color][color=#0000bb]b[/color][color=#007700]=[/color][color=#0000bb]scan1[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); }catch([/color][color=#0000bb]inputmismatchexception e1[/color][color=#007700]){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"co loi gi do: b phai la so nguyen "[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]e1[/color][color=#007700].[/color][color=#0000bb]tostring[/color][color=#007700]()); } try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x= "[/color][color=#007700]+(-[/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700])); }catch([/color][color=#0000bb]arithmeticexception e1[/color][color=#007700]){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]e1[/color][color=#007700].[/color][color=#0000bb]tostring[/color][color=#007700]()); } }}[/color] 

  5. #35
    Ngày tham gia
    Jun 2014
    Bài viết
    0
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>


    Mã nguồn PHP:
    [color=#000000]
    [/color][color=#007700]public class [/color][color=#0000bb]bai1_unit22 [/color][color=#007700]{ [/color][color=#ff8000]/* làm lại bài giải phương trình ax + b = 0 . lập trình hướng đối tượng. các hệ số nhập vào từ bàn phím. sử dụng try - catch để bẫy các lỗi khi nhập sai kiểu dữ liệu, ví dụ nhập số lại nhập chữ. bẫy lỗi chia cho 0. */ [/color][color=#007700]public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) { [/color][color=#0000bb]ptbacnhat p [/color][color=#007700]= new [/color][color=#0000bb]ptbacnhat[/color][color=#007700](); [/color][color=#0000bb]p[/color][color=#007700].[/color][color=#0000bb]nhap[/color][color=#007700](); [/color][color=#0000bb]p[/color][color=#007700].[/color][color=#0000bb]giaipt[/color][color=#007700](); }} class [/color][color=#0000bb]ptbacnhat [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700],[/color][color=#0000bb]b[/color][color=#007700];[/color][color=#ff8000]// cho nay de kieu int thi moi bat duoc loi // con de float, double thi no cho nghiem x=nan // ko hieu lam, de tim hieu sau, tien toi cac bai khac da [/color][color=#007700]public [/color][color=#0000bb]int geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]void seta[/color][color=#007700]([/color][color=#0000bb]int a[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]int getb[/color][color=#007700]() { return [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void setb[/color][color=#007700]([/color][color=#0000bb]int b[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void nhap[/color][color=#007700]() { [/color][color=#0000bb]scanner input [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap he so cho phuong trinh:"[/color][color=#007700]); try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"a="[/color][color=#007700]); [/color][color=#0000bb]seta[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"b="[/color][color=#007700]); [/color][color=#0000bb]setb[/color][color=#007700]([/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: " [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } } public [/color][color=#0000bb]void giaipt[/color][color=#007700]() { try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x=" [/color][color=#007700]+ -[/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700]); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: " [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>

  6. #36
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    bài hay quá

  7. #37
    Ngày tham gia
    Feb 2015
    Bài viết
    0
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>


    Mã nguồn PHP:
    [color=#000000]
    [/color][color=#ff8000]/** 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.*/[/color][color=#0000bb]package bai22[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]inputmismatchexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];[/color][color=#ff8000]/**** @author tran*/[/color][color=#007700]public class [/color][color=#0000bb]trycatchfinal [/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) [/color][color=#0000bb]throws myexception [/color][color=#007700]{ [/color][color=#0000bb]ptbacnhat a [/color][color=#007700]= new [/color][color=#0000bb]ptbacnhat[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]nhap[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]timnghiem[/color][color=#007700]([/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]geta[/color][color=#007700](), [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]getb[/color][color=#007700]()); }}class [/color][color=#0000bb]ptbacnhat[/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700]; private [/color][color=#0000bb]int b[/color][color=#007700]; public [/color][color=#0000bb]int geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]void seta[/color][color=#007700]([/color][color=#0000bb]int a[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700]; } public [/color][color=#0000bb]int getb[/color][color=#007700]() { return [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void setb[/color][color=#007700]([/color][color=#0000bb]int b[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]; } public [/color][color=#0000bb]void nhap[/color][color=#007700](){ [/color][color=#0000bb]scanner nhap [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); try{ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"a= "[/color][color=#007700]); [/color][color=#0000bb]seta[/color][color=#007700]([/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"b= "[/color][color=#007700]); [/color][color=#0000bb]setb[/color][color=#007700]([/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()); }catch ([/color][color=#0000bb]inputmismatchexception e[/color][color=#007700]){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error "[/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } } public [/color][color=#0000bb]void timnghiem[/color][color=#007700]([/color][color=#0000bb]int a[/color][color=#007700],[/color][color=#0000bb]int b[/color][color=#007700]){ if([/color][color=#0000bb]a[/color][color=#007700]==[/color][color=#0000bb]0[/color][color=#007700]){ try{ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x= "[/color][color=#007700]+ -[/color][color=#0000bb]b[/color][color=#007700]/[/color][color=#0000bb]a[/color][color=#007700]); }catch([/color][color=#0000bb]exception e1[/color][color=#007700]){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"error: "[/color][color=#007700]+[/color][color=#0000bb]e1[/color][color=#007700]); } }else{ [/color][color=#0000bb]float m [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700]; [/color][color=#0000bb]float n [/color][color=#007700]= [/color][color=#0000bb]b[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"x= "[/color][color=#007700]+ (float)(-[/color][color=#0000bb]m[/color][color=#007700]/[/color][color=#0000bb]n[/color][color=#007700])); } }}[/color] 
    </blockquote></div>
    </div>
    </div>

  8. #38
    Ngày tham gia
    Apr 2015
    Bài viết
    0
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>
    import java.util.*;
    public class try_catch {
    public static void main(string[]args){
    try {
    scanner snhap=new scanner(system.in);
    system.out.println("giải pt ax+b=0");
    system.out.print("nhập số a: ");
    int a=snhap.nextint();
    system.out.print("nhập số b: ");
    int b=snhap.nextint();

    system.out.println("nghiệm của phương trình là: "+b / a);
    } catch (inputmismatchexception e) {
    system.out.print("có lỗi xảy ra: "+e);
    }catch(arithmeticexception e){
    system.out.print("có lỗi xảy ra: "+e);
    }catch(exception e){
    system.out.println("có lỗi xảy ra: "+e);
    }

    }
    }
    </blockquote></div>
    </div>
    </div>

Trang 4 của 4 Đầu tiênĐầu tiên ... 234

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •