Trang 3 của 4 Đầu tiênĐầu tiên 1234 CuốiCuối
Kết quả 21 đến 30 của 38
  1. #21
    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]
    package beginers[/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]; public class [/color][color=#0000bb]trycatch [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700], [/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void setab[/color][color=#007700](){ [/color][color=#0000bb]scanner in [/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]"entry the value of variable a: "[/color][color=#007700]); [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]in[/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 1 " [/color][color=#007700]+[/color][color=#0000bb]e[/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]"entery the value of variable b: "[/color][color=#007700]); [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]in[/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 2:" [/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } }[/color][color=#ff8000]// method setab. [/color][color=#007700]public [/color][color=#0000bb]int geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; }[/color][color=#ff8000]// method geta. [/color][color=#007700]public [/color][color=#0000bb]int getb[/color][color=#007700](){ return [/color][color=#0000bb]b[/color][color=#007700]; }[/color][color=#ff8000]//method getb. [/color][color=#007700]public [/color][color=#0000bb]void change[/color][color=#007700](){ try { if([/color][color=#0000bb]a[/color][color=#007700]==[/color][color=#0000bb]0 [/color][color=#007700]&& [/color][color=#0000bb]b[/color][color=#007700]==[/color][color=#0000bb]0[/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 vo so nghiem! "[/color][color=#007700]); }else if([/color][color=#0000bb]a[/color][color=#007700]==[/color][color=#0000bb]0 [/color][color=#007700]&& [/color][color=#0000bb]b[/color][color=#007700]!=[/color][color=#0000bb]0[/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 vo nghiem! "[/color][color=#007700]); }else { [/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 pt: " [/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 here! " [/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } }[/color][color=#ff8000]//method change! [/color][color=#007700]public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string args [/color][color=#007700][]){ [/color][color=#0000bb]trycatch a [/color][color=#007700]= new [/color][color=#0000bb]trycatch[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]setab[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]change[/color][color=#007700](); }[/color][color=#ff8000]// method main.[/color][color=#007700]}[/color] 
    </blockquote></div>
    </div>
    </div>

  2. #22
    Ngày tham gia
    Apr 2016
    Bài viết
    0
    bài của mình nè: :d
    <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]
    package com[/color][color=#007700].[/color][color=#0000bb]hanhnv[/color][color=#007700].[/color][color=#0000bb]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]; public class [/color][color=#0000bb]bai22 [/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]mathcal mc [/color][color=#007700]= new [/color][color=#0000bb]mathcal[/color][color=#007700](); try { [/color][color=#0000bb]mc[/color][color=#007700].[/color][color=#0000bb]inputdata[/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]"******************"[/color][color=#007700]); [/color][color=#0000bb]mc[/color][color=#007700].[/color][color=#0000bb]showresult[/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: please enter number, not string!"[/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: a mustn\'s equals zero!"[/color][color=#007700]); } } } class [/color][color=#0000bb]mathcal [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700], [/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void inputdata[/color][color=#007700]() { [/color][color=#0000bb]scanner s [/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]"enter a: "[/color][color=#007700]); [/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]nextint[/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]"enter b: "[/color][color=#007700]); [/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); } public [/color][color=#0000bb]void showresult[/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]a [/color][color=#007700]+ [/color][color=#dd0000]"x + " [/color][color=#007700]+ [/color][color=#0000bb]b [/color][color=#007700]+ [/color][color=#dd0000]" = 0"[/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]+ (-[/color][color=#0000bb]b [/color][color=#007700]/ [/color][color=#0000bb]a[/color][color=#007700])); } }[/color] 
    </blockquote></div>
    </div>
    </div>

  3. #23
    Ngày tham gia
    Dec 2014
    Bài viết
    0
    cho em hỏi là sao eclipse của em mỗi lần khai báo import là nó báo lỗi không nhận ạ? ai biết giải thích hộ em với.
    ví dụ như: import basic.numbershandling; này thì nó cứ báo lỗi ạ

    ảnh ở bên dưới ạ

  4. #24
    Ngày tham gia
    Apr 2014
    Bài viết
    0
    sao bài này k nói rõ và cụ thể hơn 1 tý về throw và throws thế anh tiasangmoi92, 2 cái này em đang còn mơ hồ quá.

  5. #25
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    Trích dẫn Gửi bởi mr_gru
    sao bài này k nói rõ và cụ thể hơn 1 tý về throw và throws thế anh tiasangmoi92, 2 cái này em đang còn mơ hồ quá.
    throws là dùng trên khai báo phương thức còn throw là dùng trong thân phương thức. trên khai báo phương thức nếu dùng throws rồi thì ko cần dùng try catch nữa, còn throw dùng trong thân hàm để ném ngoại lệ ra bên ngoài.

  6. #26
    Ngày tham gia
    Oct 2014
    Bài viết
    1
    cho mình hỏi , mình để kiểu int thì bắt lỗi chia cho 0 dc, còn chuyển a,b sang kiểu float thì lại ko bắt lỗi dc.
    <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 bai22trycatch[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].*; [/color][color=#ff8000]/** * 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. * * @author admin */[/color][color=#007700]public class [/color][color=#0000bb]baitap [/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]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]); [/color][color=#0000bb]int a[/color][color=#007700],[/color][color=#0000bb]b[/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]"nhập a: "[/color][color=#007700]); [/color][color=#0000bb]a[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhập b: "[/color][color=#007700]); [/color][color=#0000bb]b[/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].[/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 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]"lỗi chia cho 0"[/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]"nhập sai kiểu dữ liệu "[/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]"có lỗi gì đó xảy ra "[/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]"tên lỗi là: " [/color][color=#007700]+ [/color][color=#0000bb]e1[/color][color=#007700]); } finally { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"có lỗi hay không thì cái dòng cuối cùng này vẫn được in ra!"[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>

  7. #27
    Ngày tham gia
    Feb 2015
    Bài viết
    0
    Mã nguồn PHP:
    [color=#000000]
    package trycatchfinally[/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]; class [/color][color=#0000bb]formula[/color][color=#007700]{static [/color][color=#0000bb]scanner inp[/color][color=#007700];public static [/color][color=#0000bb]void work[/color][color=#007700](){[/color][color=#0000bb]float a[/color][color=#007700]; [/color][color=#0000bb]float b[/color][color=#007700];[/color][color=#0000bb]float x[/color][color=#007700];[/color][color=#0000bb]inp [/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]"put a= "[/color][color=#007700]);[/color][color=#0000bb]a[/color][color=#007700]=[/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextfloat[/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]"put b= "[/color][color=#007700]);[/color][color=#0000bb]b[/color][color=#007700]=[/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextfloat[/color][color=#007700]();[/color][color=#0000bb]x[/color][color=#007700]=(float)-[/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]"phuong trinh "[/color][color=#007700]+ [/color][color=#0000bb]a[/color][color=#007700]+[/color][color=#dd0000]"x+"[/color][color=#007700]+[/color][color=#0000bb]b[/color][color=#007700]+[/color][color=#dd0000]"=0 co nghiem la: "[/color][color=#007700]+[/color][color=#0000bb]x[/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 class [/color][color=#0000bb]doublefunction [/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]formula[/color][color=#007700].[/color][color=#0000bb]work[/color][color=#007700]();try{[/color][color=#0000bb]float y[/color][color=#007700];[/color][color=#0000bb]y[/color][color=#007700]=-[/color][color=#0000bb]7[/color][color=#007700]/[/color][color=#0000bb]0[/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]y[/color][color=#007700]);}catch([/color][color=#0000bb]exception 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]"error in thread main: "[/color][color=#007700]+[/color][color=#0000bb]a[/color][color=#007700]);} } }[/color] 

  8. #28
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    <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]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]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>

  9. #29
    Ngày tham gia
    Jun 2014
    Bài viết
    0
    Trích dẫn Gửi bởi kiethohoai
    <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]
    package beginers[/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]; public class [/color][color=#0000bb]trycatch [/color][color=#007700]{ private [/color][color=#0000bb]int a[/color][color=#007700], [/color][color=#0000bb]b[/color][color=#007700]; public [/color][color=#0000bb]void setab[/color][color=#007700](){ [/color][color=#0000bb]scanner in [/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]"entry the value of variable a: "[/color][color=#007700]); [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]in[/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 1 " [/color][color=#007700]+[/color][color=#0000bb]e[/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]"entery the value of variable b: "[/color][color=#007700]); [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]in[/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 2:" [/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } }[/color][color=#ff8000]// method setab. [/color][color=#007700]public [/color][color=#0000bb]int geta[/color][color=#007700]() { return [/color][color=#0000bb]a[/color][color=#007700]; }[/color][color=#ff8000]// method geta. [/color][color=#007700]public [/color][color=#0000bb]int getb[/color][color=#007700](){ return [/color][color=#0000bb]b[/color][color=#007700]; }[/color][color=#ff8000]//method getb. [/color][color=#007700]public [/color][color=#0000bb]void change[/color][color=#007700](){ try { if([/color][color=#0000bb]a[/color][color=#007700]==[/color][color=#0000bb]0 [/color][color=#007700]&& [/color][color=#0000bb]b[/color][color=#007700]==[/color][color=#0000bb]0[/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 vo so nghiem! "[/color][color=#007700]); }else if([/color][color=#0000bb]a[/color][color=#007700]==[/color][color=#0000bb]0 [/color][color=#007700]&& [/color][color=#0000bb]b[/color][color=#007700]!=[/color][color=#0000bb]0[/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 vo nghiem! "[/color][color=#007700]); }else { [/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 pt: " [/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 here! " [/color][color=#007700]+[/color][color=#0000bb]e[/color][color=#007700]); } }[/color][color=#ff8000]//method change! [/color][color=#007700]public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string args [/color][color=#007700][]){ [/color][color=#0000bb]trycatch a [/color][color=#007700]= new [/color][color=#0000bb]trycatch[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]setab[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]change[/color][color=#007700](); }[/color][color=#ff8000]// method main.[/color][color=#007700]}[/color] 
    </blockquote></div>
    </div>
    </div>
    bài này của bạn ở phương thức change thì hình như ko nhảy vào catch đc nhỉ, vì lỗi là a==0 và b!=0 thì nó nhảy và chỗ if else rùi

  10. #30
    Ngày tham gia
    Sep 2014
    Bài viết
    0
    Trích dẫn Gửi bởi kienit
    <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]
    package ede[/color][color=#007700].[/color][color=#0000bb]cacbt[/color][color=#007700].[/color][color=#0000bb]kien[/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]; public class [/color][color=#0000bb]trycatchbt [/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]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]int a[/color][color=#007700]; [/color][color=#0000bb]int 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]"nhap a: "[/color][color=#007700]); [/color][color=#0000bb]a [/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap b: "[/color][color=#007700]); [/color][color=#0000bb]b [/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"ngiem la :" [/color][color=#007700]+ (-[/color][color=#0000bb]b [/color][color=#007700]/ [/color][color=#0000bb]a[/color][color=#007700])); } catch ([/color][color=#0000bb]arithmeticexception 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]); } 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]"error nhap sai kieu du lieu: " [/color][color=#007700]+ [/color][color=#0000bb]e1[/color][color=#007700]); } } }[/color] 
    </blockquote></div>
    </div>
    </div>
    bài này hình như không liên quan đến hướng đối tượng nhỉ

Trang 3 của 4 Đầu tiênĐầu tiên 1234 CuốiCuối

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
  •