-
09-11-2014, 07:00 AM #31Junior Member
- Ngày tham gia
- Apr 2015
- Bài viết
- 0
Gửi bởi hatb
Gửi bởi hatb
đưa ra đúng ko mọi người
-
09-11-2014, 07:00 AM #32Junior Member
- 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]
-
09-15-2014, 07:00 AM #33Junior Member
- 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>
Gửi bởi tuanleedragon
</div>
</div>
Gửi bởi tuanleedragon
-
01-16-2015, 07:00 AM #34Junior Member
- 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]
-
01-23-2015, 07:00 AM #35Junior Member
- 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]
</div>
</div>
-
-
09-15-2015, 07:00 AM #37Junior Member
- 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]
</div>
</div>
-
05-29-2016, 07:00 AM #38Junior Member
- 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>
Khu chung cư cao cấp The Esme Dĩ An đầu tư bởi Công ty TNHH Đầu tư Xây dựng Thiên Hà – Băng Dương văn hoá đa dạng gần trung tâm đầu tư dài hạn. The Esme Dĩ An giagocchudautu.com văn hoá đa dạng...
Dự án chung cư The Esme Dĩ An sát trung tâm