Chủ đề: Bài 9: Mảng trong Java!
-
05-23-2014, 07:00 AM #61Member
- Ngày tham gia
- Jul 2015
- Bài viết
- 54
Mã nguồn PHP:[color=#000000]
[/color][color=#007700]if([/color][color=#0000bb]ten[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]arrstring[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]])); [/color][color=#0000bb]x[/color][color=#007700]=[/color][color=#0000bb]x[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700]; } if([/color][color=#0000bb]x[/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]"ten "[/color][color=#007700]+[/color][color=#0000bb]ten[/color][color=#007700]+[/color][color=#dd0000]" co trong danh sach"[/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]"ten "[/color][color=#007700]+[/color][color=#0000bb]ten[/color][color=#007700]+[/color][color=#dd0000]" khong co trong danh sach"[/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]"nhap so sinh vien lon hon 0"[/color][color=#007700]);[/color]
-
05-24-2014, 07:00 AM #62Junior Member
- Ngày tham gia
- Apr 2014
- Bài viết
- 0
Gửi bởi xuanthu
for( i=0;i< n;i++) {
if(b.equals(a)){
kq=false;
system.out.println("có trong danh sách");
}else {
system.out.println("khong có trong danh sách");
break;
}
nó sẽ hiển thị đúng đó.
và bạn tạo
scanner in1=new scanner(system.in); cho a
scanner in=new scanner(system.in); cho b
riêng biệt thì nó sẽ không tự nhảy xuống hàng nữa.
-
05-24-2014, 07:00 AM #63Junior Member
- Ngày tham gia
- Apr 2015
- Bài viết
- 14
Gửi bởi xuanthu
-
05-28-2014, 07:00 AM #64Junior Member
- Ngày tham gia
- May 2014
- Bài viết
- 0
từ bài này code khá dài và chấm mất công vị vậy ở mỗi bài bạn có thể cho đáp án ở dưới luôn. để khi mình làm xong tiện so sánh và đối chiếu. mình là người mới bắt đầu tìm hiểu vào lập trình java nên ở nhiều bài thấy các bạn làm có các kiến thức mà ở các bài trước chưa có vì vậy xem đáp án của họ cũng ko hiểu hết dk
-
06-08-2014, 07:00 AM #65Junior Member
- Ngày tham gia
- Mar 2015
- Bài viết
- 0
m.n xem dùm bài này nếu mình muốn tách chổ xuất mảng ra 1 phương thức mới thì làm sao vậy.....
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bai2 (move your mouse to reveal the content)</noscript>
bai2 (open)
bai2 (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote></blockquote></div>
</div>
</div>
Mã nguồn PHP:[color=#000000]
package bai2[/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]bai2 [/color][color=#007700]{[/color][color=#0000bb]int n[/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]);public [/color][color=#0000bb]void nhapn[/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 so phan tu so nguyen n:"[/color][color=#007700]);[/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();}public [/color][color=#0000bb]void nhappt[/color][color=#007700]() {[/color][color=#0000bb]int arrayint[/color][color=#007700][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]];[/color][color=#0000bb]int tam[/color][color=#007700];for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]i[/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 phan tu thu:"[/color][color=#007700]+([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700]));[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]=[/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();}for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++) {for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<=[/color][color=#0000bb]j[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++) {if([/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]>[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]) {[/color][color=#0000bb]tam[/color][color=#007700]=[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]];[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]=[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]];[/color][color=#0000bb]arrayint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]=[/color][color=#0000bb]tam[/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]"ds sau khi sap xep:"[/color][color=#007700]);for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/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]arrayint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]);} }}[/color]
Mã nguồn PHP:[color=#000000]
package bai2[/color][color=#007700];public class [/color][color=#0000bb]main [/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]bai2 bai2 [/color][color=#007700]= new [/color][color=#0000bb]bai2[/color][color=#007700]();[/color][color=#0000bb]bai2[/color][color=#007700].[/color][color=#0000bb]nhapn[/color][color=#007700]();[/color][color=#0000bb]bai2[/color][color=#007700].[/color][color=#0000bb]nhappt[/color][color=#007700]();}}[/color]
-
06-21-2014, 07:00 AM #66Junior 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>
Mã nguồn PHP:[color=#000000]
import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];public class [/color][color=#0000bb]arrdemo [/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]string stu[/color][color=#007700], [/color][color=#0000bb]findstu[/color][color=#007700]; [/color][color=#0000bb]string [/color][color=#007700][] [/color][color=#0000bb]arrstu [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]3[/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]); for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]3[/color][color=#007700]; [/color][color=#0000bb]i[/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 tên sinh viên thứ: "[/color][color=#007700]+[/color][color=#0000bb]i[/color][color=#007700]); [/color][color=#0000bb]stu [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]arrstu[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]=[/color][color=#0000bb]stu[/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 sv muôn tìm: "[/color][color=#007700]); [/color][color=#0000bb]findstu [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/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]"sv :"[/color][color=#007700]+[/color][color=#0000bb]findstu[/color][color=#007700]); for([/color][color=#0000bb]int i [/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]< [/color][color=#0000bb]3[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if([/color][color=#0000bb]findstu[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]arrstu[/color][color=#007700][[/color][color=#0000bb]i[/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]"sv có trong ds!"[/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]"khong có sv trong ds!"[/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=#ff8000]//bài 2 [/color][color=#0000bb]int [/color][color=#007700][] [/color][color=#0000bb]arrn [/color][color=#007700]= {[/color][color=#0000bb]2[/color][color=#007700],[/color][color=#0000bb]8[/color][color=#007700],[/color][color=#0000bb]6[/color][color=#007700],[/color][color=#0000bb]1[/color][color=#007700],[/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]9[/color][color=#007700],[/color][color=#0000bb]4[/color][color=#007700],[/color][color=#0000bb]7[/color][color=#007700]}; for([/color][color=#0000bb]int i [/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]arrn[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j [/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]<=[/color][color=#0000bb]i[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++) { if ([/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]<[/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]) { [/color][color=#0000bb]int tmp [/color][color=#007700]=[/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]tmp[/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]"mang sau khi sap xep: "[/color][color=#007700]); for ([/color][color=#0000bb]int i [/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]<[/color][color=#0000bb]arrn[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( +[/color][color=#0000bb]arrn[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]" "[/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]scanner sl [/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 so hang:"[/color][color=#007700]); [/color][color=#0000bb]int m [/color][color=#007700]= [/color][color=#0000bb]sl[/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 so cot:"[/color][color=#007700]); [/color][color=#0000bb]int n [/color][color=#007700]= [/color][color=#0000bb]sl[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]int [/color][color=#007700][][] [/color][color=#0000bb]arrma [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]m[/color][color=#007700]][[/color][color=#0000bb]n[/color][color=#007700]]; [/color][color=#0000bb]int [/color][color=#007700][][] [/color][color=#0000bb]arrmb [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]m[/color][color=#007700]][[/color][color=#0000bb]n[/color][color=#007700]]; [/color][color=#0000bb]int [/color][color=#007700][][] [/color][color=#0000bb]arrmc [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]m[/color][color=#007700]][[/color][color=#0000bb]n[/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 hang 1"[/color][color=#007700]); for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++) { [/color][color=#0000bb]arrma[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]sl[/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 hang 2"[/color][color=#007700]); { for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++) { [/color][color=#0000bb]arrmb[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]sl[/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]"ma trận 1 là : "[/color][color=#007700]); for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]" "[/color][color=#007700]+[/color][color=#0000bb]arrma[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"ma trận 2 là : "[/color][color=#007700]); for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]" "[/color][color=#007700]+[/color][color=#0000bb]arrmb[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/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]); } for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++) { [/color][color=#0000bb]arrmc[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]]= [/color][color=#0000bb]arrma[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]]+[/color][color=#0000bb]arrmb[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/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ổng 2 ma trận: "[/color][color=#007700]); for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]m[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++) { for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]n[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]" "[/color][color=#007700]+[/color][color=#0000bb]arrmc[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/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]
</div>
</div>
-
06-28-2014, 07:00 AM #67Junior Member
- Ngày tham gia
- Feb 2015
- Bài viết
- 0
admin oi em nghi la anh nen them nhieu vi du minh hoa hon.....nhieu luc doc cha hieu cai j
-
07-06-2014, 07:00 AM #68Junior Member
- Ngày tham gia
- Mar 2014
- Bài viết
- 4
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bai01 (move your mouse to reveal the content)</noscript>
bai01 (open)
bai01 (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package edu[/color][color=#007700].[/color][color=#0000bb]ducky[/color][color=#007700].[/color][color=#0000bb]basic[/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]arraydemo [/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 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]);[/color][color=#0000bb]int numberstudents[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so luong sinh vien:"[/color][color=#007700]);[/color][color=#0000bb]numberstudents [/color][color=#007700]= [/color][color=#0000bb]integer[/color][color=#007700].[/color][color=#0000bb]parseint[/color][color=#007700]([/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]());[/color][color=#0000bb]string liststudents[/color][color=#007700][] = new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]numberstudents[/color][color=#007700]]; for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]liststudents[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"ten cua sinh vien thu " [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]":"[/color][color=#007700]);[/color][color=#0000bb]liststudents[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();}[/color][color=#0000bb]string find[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap ten sinh vien can tim:"[/color][color=#007700]);[/color][color=#0000bb]find [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]boolean result [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700];for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]liststudents[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) {if ([/color][color=#0000bb]find[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]liststudents[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]) == [/color][color=#0000bb]0[/color][color=#007700]) {[/color][color=#0000bb]result [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700];}}if ([/color][color=#0000bb]result [/color][color=#007700]== [/color][color=#0000bb]true[/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]"sinh vien co ten " [/color][color=#007700]+ [/color][color=#0000bb]find [/color][color=#007700]+ [/color][color=#dd0000]" da duoc tim thay"[/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]"khong tim thay sinh vien ten " [/color][color=#007700]+ [/color][color=#0000bb]find[/color][color=#007700]);[/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700]();}}[/color]
</div>
</div>
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bai02 (move your mouse to reveal the content)</noscript>
bai02 (open)
bai02 (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package edu[/color][color=#007700].[/color][color=#0000bb]ducky[/color][color=#007700].[/color][color=#0000bb]basic[/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]arrayarrangement [/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 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]);[/color][color=#0000bb]int n[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap n:"[/color][color=#007700]);[/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();[/color][color=#0000bb]int a[/color][color=#007700][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]];for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so nguyen thu "[/color][color=#007700]+([/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700])+[/color][color=#dd0000]" :"[/color][color=#007700]);[/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();} [/color][color=#ff8000]//sap xep[/color][color=#007700]for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++){for([/color][color=#0000bb]int j [/color][color=#007700]= [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]j [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){if([/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] > [/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]){[/color][color=#0000bb]int temp [/color][color=#007700]= [/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]];[/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]];[/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]temp[/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]"day so nguyen sau khi duoc sap xep"[/color][color=#007700]);for([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++)[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]" "[/color][color=#007700]);[/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700]();}}[/color]
</div>
</div>
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bai03 (move your mouse to reveal the content)</noscript>
bai03 (open)
bai03 (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package edu[/color][color=#007700].[/color][color=#0000bb]ducky[/color][color=#007700].[/color][color=#0000bb]basic[/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]matriz [/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 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]);[/color][color=#0000bb]int n[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"input number line and column:"[/color][color=#007700]);[/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();[/color][color=#0000bb]int array1[/color][color=#007700][][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]][[/color][color=#0000bb]n[/color][color=#007700]];[/color][color=#0000bb]int array2[/color][color=#007700][][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]][[/color][color=#0000bb]n[/color][color=#007700]]; [/color][color=#0000bb]int i[/color][color=#007700], [/color][color=#0000bb]j[/color][color=#007700];for ([/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++)for ([/color][color=#0000bb]j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"input array1[" [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]"][" [/color][color=#007700]+ [/color][color=#0000bb]j [/color][color=#007700]+ [/color][color=#dd0000]"]:"[/color][color=#007700]);[/color][color=#0000bb]array1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();}for ([/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) for ([/color][color=#0000bb]j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++) {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"input array2[" [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]"][" [/color][color=#007700]+ [/color][color=#0000bb]j [/color][color=#007700]+ [/color][color=#dd0000]"]:"[/color][color=#007700]);[/color][color=#0000bb]array2[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();}[/color][color=#ff8000]//addition array1 and array2[/color][color=#0000bb]int array3[/color][color=#007700][][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]][[/color][color=#0000bb]n[/color][color=#007700]];for ([/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++){for ([/color][color=#0000bb]j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]j [/color][color=#007700]< [/color][color=#0000bb]n[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){[/color][color=#0000bb]array3[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]array1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] + [/color][color=#0000bb]array2[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]array3[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]]+[/color][color=#dd0000]" "[/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]in[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700]();}}[/color]
</div>
</div>
-
07-08-2014, 07:00 AM #69Junior Member
- Ngày tham gia
- Jun 2014
- Bài viết
- 0
Gửi bởi xuanthu
-
07-09-2014, 07:00 AM #70Junior Member
- Ngày tham gia
- Apr 2015
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>code bai 3 chuan nhat! (move your mouse to reveal the content)</noscript>
code bai 3 chuan nhat! (open)
code bai 3 chuan nhat! (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote></blockquote></div>
</div>
</div>
Mã nguồn PHP:[color=#000000]
[/color]
import java.util.scanner;
public class matrix {
private int[][] matrix1, matrix2, summatrix; // summatrix de luu tong 2 ma
// tran
private int numberrow, numbercolumn;
public matrix() {
system.out.println("nhap so hang va so cot cua 2 ma tran : ");
scanner inp = new scanner(system.in);
numberrow = inp.nextint(); // nhap so hang
numbercolumn = inp.nextint(); // nhap so cot
matrix1 = new int[numberrow][numbercolumn];
matrix2 = new int[numberrow][numbercolumn];
}
public void input(int matrix[][]) {
scanner inp = new scanner(system.in);
for (int i = 0; i < numberrow; i++)
// nhap ma tran dau tien
for (int j = 0; j < numbercolumn; j++) {
system.out.print("a[" + i + "][" + j + "] = ");
matrix[j] = inp.nextint();
}
}
public void show(int matrix[][]) { // dua ma tran ra man hinh
system.out.println();
for (int i = 0; i < numberrow; i++) {
for (int j = 0; j < numbercolumn; j++)
system.out.print(matrix[j] + " ");
system.out.print("
");
}
}
public void sumoftowmatrix() { // tinh tong 2 ma tran
summatrix = new int[numberrow][numbercolumn];
int i = 0, j;
while(i<numberrow){
for (j = 0; j<numbercolumn; j++)
summatrix[j] = matrix1[j] + matrix2[j];
i++;
}
}
public static void main(string[] args) {
matrix mt = new matrix();
system.out.println("nhap cac phan tu cho ma tran thu nhat : ");
mt.input(mt.matrix1);
system.out.println("nhap cac phan tu cho ma tran thu hai : ");
mt.input(mt.matrix2);
system.out.println("ma tran thu nhat da nhap la : ");
mt.show(mt.matrix1);
system.out.println("
ma tran thu hai da nhap la : ");
mt.show(mt.matrix2);
mt.sumoftowmatrix();
system.out.println("
tong 2 ma tran la : ");
mt.show(mt.summatrix);
}
}
Khu dự án Diamond Alnata Plus phát triển bởi Gamuda Land thiết kế hợp lý nằm trung tâm thông gió tự nhiên. Diamond Alnata Plus Tân Phú thiết kế hợp lý sống đích thực ngay giữa trung tâm. Căn hộ cách...
Khu dự án Diamond Alnata Plus giáp trung tâm