-
07-22-2014, 07:00 AM #41Junior Member
- Ngày tham gia
- Jun 2014
- Bài viết
- 0
ẹc..học về break vs continue mà sao m.n ko thấy dùng vậy..haizzz
-
07-22-2014, 07:00 AM #42Junior Member
- Ngày tham gia
- Feb 2015
- Bài viết
- 0
định tham khảo xem có ai làm bằng lệnh break hoặc continue ko để tham khảo mà e chỉ làm đc theo for vs if thôi...mong pro kiểm tra hộ e
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>baitap (move your mouse to reveal the content)</noscript>
baitap (open)
baitap (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã:import java.util.scanner; public class newmain { public static void main(string[] args) { int i; scanner sc = new scanner(system.in); system.out.print("nhập tổng số sinh viên: "); int n = sc.nextint(); string a [] = new string[n]; sc = new scanner(system.in); for (i = 0;i < n;i++) { system.out.print("nhập tên sinh viên thứ " + (i + 1) + ": "); a[i] = sc.nextline(); } system.out.println(""); system.out.println("danh sách sinh viên vừa nhập: "); for (i = 0;i < n;i++) { system.out.println("thứ " + (i + 1) + ": " + a[i]); } system.out.println(""); system.out.print("nhập tên sinh viên muốn tim: "); string b = sc.nextline(); system.out.println("tên sinh viên bạn mới nhập là: " + b); for (i = 0;i < n;i++) { if (b.equals(a[i])) { system.out.println("có trong danh sách" + " " + "vịt trí của sinh viên này trong danh sách là: " + (i + 1)); }else{ system.out.println("không có tên trong danh sách này!!!"); } } } }
</div>
</div>
-
07-28-2014, 07:00 AM #43Junior Member
- Ngày tham gia
- Mar 2015
- Bài viết
- 0
bạn xem dùm mình tại sao không cho nhập tên người thứ 1. cảm ơn
<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 vidu[/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]vidu [/color][color=#007700]{ [/color][color=#ff8000]/** * @param args the command line arguments */ [/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 timkiem [/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]string arrten[/color][color=#007700][]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so hoc sinh trong lop:"[/color][color=#007700]); [/color][color=#0000bb]int n [/color][color=#007700]= [/color][color=#0000bb]timkiem[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]arrten [/color][color=#007700]= new [/color][color=#0000bb]string[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap ten hoc sinh thu " [/color][color=#007700]+ ([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700])); [/color][color=#0000bb]arrten [/color][color=#007700]= [/color][color=#0000bb]timkiem[/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]"nhap ten hoc sinh can tim: "[/color][color=#007700]); [/color][color=#0000bb]string tim [/color][color=#007700]= [/color][color=#0000bb]timkiem[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]labelall[/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]10 [/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){ if ([/color][color=#0000bb]arrten[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]tim[/color][color=#007700])){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]" day la hoc sinh thu: " [/color][color=#007700]+ ([/color][color=#0000bb]j[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700])); break [/color][color=#0000bb]labelall[/color][color=#007700]; } } }}[/color]
</div>
</div>
-
08-02-2014, 07:00 AM #44Junior Member
- Ngày tham gia
- Apr 2016
- Bài viết
- 0
Gửi bởi hell3880
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>da sua (move your mouse to reveal the content)</noscript>
da sua (open)
da sua (close)
</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]newmain [/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 timkiem [/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]string arrten[/color][color=#007700][]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so hoc sinh trong lop:"[/color][color=#007700]); [/color][color=#0000bb]int n [/color][color=#007700]= [/color][color=#0000bb]timkiem[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]arrten [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]]; [/color][color=#0000bb]timkiem [/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]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 ten hoc sinh thu " [/color][color=#007700]+ ([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700])); [/color][color=#0000bb]arrten[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]timkiem[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap ten hoc sinh can tim: "[/color][color=#007700]); [/color][color=#0000bb]string tim [/color][color=#007700]= [/color][color=#0000bb]timkiem[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]labelall[/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]10 [/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){ if ([/color][color=#0000bb]arrten[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]tim[/color][color=#007700])){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]" day la hoc sinh thu: " [/color][color=#007700]+ ([/color][color=#0000bb]j[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700]) + [/color][color=#dd0000]"
"[/color][color=#007700]); break [/color][color=#0000bb]labelall[/color][color=#007700]; } } }}[/color]
</div>
</div>
-
-
09-01-2014, 07:00 AM #46Junior Member
- Ngày tham gia
- Feb 2015
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bai ve nha (move your mouse to reveal the content)</noscript>
bai ve nha (open)
bai ve nha (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]arrays[/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]/*** bài 1: nhập 1 danh sách họ tên sinh viên 1 lớp học vào 1 mảng n phần tử. sắp* xếp theo thứ tự a, b, c ... rồi dùng thuật toán tìm kiếm nhị phân, tìm kiếm* chính xác tên sinh viên vừa nhập và in ra màn hình số thứ tự của sinh viên* đó!*/ [/color][color=#007700]public class [/color][color=#0000bb]buoi10 [/color][color=#007700]{ static [/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]); public [/color][color=#0000bb]void nhapsinhvien[/color][color=#007700]([/color][color=#0000bb]int sosv[/color][color=#007700], [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv[/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 lop hoc co " [/color][color=#007700]+ [/color][color=#0000bb]sosv [/color][color=#007700]+ [/color][color=#dd0000]" sinh vien: "[/color][color=#007700]); [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/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]sosv[/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]"sinh vien 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]htsv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } } public [/color][color=#0000bb]void xuatsinhvien[/color][color=#007700]([/color][color=#0000bb]int sosv[/color][color=#007700], [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"stt\tho va ten"[/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]sosv[/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]"
" [/color][color=#007700]+ ([/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]) + [/color][color=#dd0000]"\t" [/color][color=#007700]+ [/color][color=#0000bb]htsv[/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](); } public [/color][color=#0000bb]void sapxepsv[/color][color=#007700]([/color][color=#0000bb]int sosv[/color][color=#007700], [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv[/color][color=#007700]) { [/color][color=#0000bb]arrays[/color][color=#007700].[/color][color=#0000bb]sort[/color][color=#007700]([/color][color=#0000bb]htsv[/color][color=#007700]); } public [/color][color=#0000bb]int checksv[/color][color=#007700]([/color][color=#0000bb]string htsearch[/color][color=#007700], [/color][color=#0000bb]int sosv[/color][color=#007700], [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv[/color][color=#007700]) { [/color][color=#0000bb]int index [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700], [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]sosv [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]int dem [/color][color=#007700]= -[/color][color=#0000bb]1[/color][color=#007700]; while ([/color][color=#0000bb]index 0[/color][color=#007700]) { [/color][color=#0000bb]dem [/color][color=#007700]= ([/color][color=#0000bb]index [/color][color=#007700]+ [/color][color=#0000bb]n[/color][color=#007700]) / [/color][color=#0000bb]2[/color][color=#007700]; if ([/color][color=#0000bb]htsv[/color][color=#007700][[/color][color=#0000bb]dem[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]htsearch[/color][color=#007700])) { return [/color][color=#0000bb]dem [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; } if ([/color][color=#0000bb]htsearch[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]htsv[/color][color=#007700][[/color][color=#0000bb]dem[/color][color=#007700]]) > [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]index [/color][color=#007700]= [/color][color=#0000bb]dem [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; } else { [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]dem [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]; } } return -[/color][color=#0000bb]1[/color][color=#007700]; } public [/color][color=#0000bb]void searchsv[/color][color=#007700]( [/color][color=#0000bb]int sosv[/color][color=#007700], [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
nhap sinh vien can tim: "[/color][color=#007700]); [/color][color=#0000bb]string htsearch[/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]int check [/color][color=#007700]= [/color][color=#0000bb]checksv[/color][color=#007700]([/color][color=#0000bb]htsearch[/color][color=#007700], [/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/color][color=#007700]); if([/color][color=#0000bb]check[/color][color=#007700]!=-[/color][color=#0000bb]1[/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 can tim co stt = "[/color][color=#007700]+[/color][color=#0000bb]check[/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]"sinh vien vua nhap khong ton tai"[/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]buoi10 test [/color][color=#007700]= new [/color][color=#0000bb]buoi10[/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]int sosv [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]htsv [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]sosv[/color][color=#007700]]; [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]nhapsinhvien[/color][color=#007700]([/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/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]"
lop co " [/color][color=#007700]+ [/color][color=#0000bb]sosv [/color][color=#007700]+ [/color][color=#dd0000]" sinh vien:"[/color][color=#007700]); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]xuatsinhvien[/color][color=#007700]([/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/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]sosv[/color][color=#007700]+[/color][color=#dd0000]" sinh vien sau khi sap xep: "[/color][color=#007700]); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]sapxepsv[/color][color=#007700]([/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/color][color=#007700]); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]xuatsinhvien[/color][color=#007700]([/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/color][color=#007700]); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]searchsv[/color][color=#007700]([/color][color=#0000bb]sosv[/color][color=#007700], [/color][color=#0000bb]htsv[/color][color=#007700]); }}[/color]
</div>
</div>
-
10-02-2014, 07:00 AM #47Junior Member
- Ngày tham gia
- Feb 2015
- Bài viết
- 0
@tiasangmoi
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>bài đã chạy tốt. mong có nhận xét (move your mouse to reveal the content)</noscript>
bài đã chạy tốt. mong có nhận xét (open)
bài đã chạy tốt. mong có nhận xét (close)
</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 edu[/color][color=#007700].[/color][color=#0000bb]min[/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]arrays[/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 tommy_phan*/[/color][color=#007700]public class [/color][color=#0000bb]bai10 [/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so sinh vien: "[/color][color=#007700]); [/color][color=#0000bb]int n [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]string [/color][color=#007700][][/color][color=#0000bb]a [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]]; [/color][color=#0000bb]string check[/color][color=#007700]; [/color][color=#0000bb]int middle[/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 sinh vien 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]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]"danh sach sau khi sap xep"[/color][color=#007700]); [/color][color=#0000bb]arrays[/color][color=#007700].[/color][color=#0000bb]sort[/color][color=#007700]([/color][color=#0000bb]a[/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=#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]]); } do{ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap ten sv can tim: "[/color][color=#007700]); [/color][color=#0000bb]string name [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]int left [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]int right [/color][color=#007700]= [/color][color=#0000bb]n[/color][color=#007700]-[/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#ff8000]// trong lenh do while la tim lkiem nhi phan [/color][color=#007700]do { [/color][color=#0000bb]middle [/color][color=#007700]= ([/color][color=#0000bb]right[/color][color=#007700]+[/color][color=#0000bb]left[/color][color=#007700])/[/color][color=#0000bb]2[/color][color=#007700]; if([/color][color=#0000bb]name [/color][color=#007700].[/color][color=#0000bb]equals [/color][color=#007700]([/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]middle[/color][color=#007700]]) )break; else { [/color][color=#ff8000]// .compareto hinh nhu la phep tru [/color][color=#007700]if([/color][color=#0000bb]name [/color][color=#007700].[/color][color=#0000bb]compareto [/color][color=#007700]([/color][color=#0000bb]a[/color][color=#007700][[/color][color=#0000bb]middle[/color][color=#007700]])<[/color][color=#0000bb]0[/color][color=#007700]) [/color][color=#0000bb]right [/color][color=#007700]= [/color][color=#0000bb]middle [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]; else [/color][color=#0000bb]left [/color][color=#007700]= [/color][color=#0000bb]middle [/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700]; } } while ([/color][color=#0000bb]left[/color][color=#007700]<=[/color][color=#0000bb]right[/color][color=#007700]); if([/color][color=#0000bb]left[/color][color=#007700]<=[/color][color=#0000bb]right[/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]name[/color][color=#007700]+[/color][color=#dd0000]">> o vi tri "[/color][color=#007700]+([/color][color=#0000bb]middle[/color][color=#007700]+[/color][color=#0000bb]1[/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]"sv <<"[/color][color=#007700]+[/color][color=#0000bb]name[/color][color=#007700]+[/color][color=#dd0000]">> ko thay"[/color][color=#007700]); do{ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"tiep tuc an y. dung lai an n: "[/color][color=#007700]); [/color][color=#0000bb]check [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if([/color][color=#0000bb]check [/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"y"[/color][color=#007700])||[/color][color=#0000bb]check [/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"n"[/color][color=#007700])) break; else [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap sai."[/color][color=#007700]); }while ([/color][color=#0000bb]check [/color][color=#007700].[/color][color=#0000bb]compareto [/color][color=#007700]([/color][color=#dd0000]"y"[/color][color=#007700]) !=[/color][color=#0000bb]0[/color][color=#007700]||[/color][color=#0000bb]check [/color][color=#007700].[/color][color=#0000bb]compareto [/color][color=#007700]([/color][color=#dd0000]"n"[/color][color=#007700]) !=[/color][color=#0000bb]0[/color][color=#007700]); }while ([/color][color=#0000bb]check [/color][color=#007700].[/color][color=#0000bb]equals [/color][color=#007700]([/color][color=#dd0000]"y"[/color][color=#007700]) ); } }[/color]
</div>
</div>
-
01-29-2015, 07:00 AM #48Junior Member
- Ngày tham gia
- Jan 2015
- Bài viết
- 0
* @author quanghuy
*/
import java.util.scanner;
public class ex1 {
public static void main(string[] args) {
scanner input = new scanner(system.in); //khoi tao doi tuong scanner
string sv_cantim;
int num;
system.out.print("nhap so sinh vien: ");
num = input.nextint();
input.nextline();
string[] sinhvien = new string[10];
for (int i = 0; i < num; i++) {
system.out.println("nhap ho va ten sinh vien " + (i + 1) + ": ");
sinhvien = input.nextline();
}
for (int i = num; i > 0; i--) {
for (int j = 0; j < i - 1; j++) {
if (sinhvien[j].compareto(sinhvien[j + 1]) > 0) {
string temp = sinhvien[j];
sinhvien[j] = sinhvien[j + 1];
sinhvien[j + 1] = temp;
}
}
}
for (int i = 0; i < num; i++) {
system.out.println("danh sach sinh vien sau khi sap xep: "+sinhvien);
}
//search sinh vien va tim so thu tu cua sinh vien do
system.out.println("nhap ten sinh vien can tim: ");
sv_cantim = input.nextline();
for (int i = 0; i < num; i++) {
if (sv_cantim.compareto(sinhvien) == 0) {
system.out.print("sinh vien can tim la: " + sinhvien);
system.out.println("sinh vien can tim nam o so thu tu: "+(i+1));
break;
} else {
if (i == num - 1) {
system.out.println("khong co sinh vien nay");
}
}
}
-
03-16-2015, 07:00 AM #49Junior Member
- Ngày tham gia
- Feb 2015
- Bài viết
- 0
Gửi bởi viet55pm
Gửi bởi viet55pm
number tăng lên từ 1 đến 20, đầu tiên number = 1 sum sẽ tăng lên 1, number = 2 => sum = sum (=1) + 2 = 3; number = 3 => sum = sum(3) + 3 = 6; ........ number = 20 => sum = sum(=190) + 20 = 210, ra đáp án là number = 15 và
sum = 105 vì kiểm tra đk sum > 100 sẽ break ra, sum =105 là kq cuối trc khi thoát ra vòng lặp while
"căn do xuất tinh ngược này do lượng đường cao dẫn tới thương tổn dây thần kinh tại các cơ vòng khiến người bệnh bị xuất tinh ngược. thường ngày, khi xuất tinh thì cơ thắt cổ bọng đái đóng lại để...
Nguyên nhân và giải pháp cho tình trạng không xuất tinh ở phái mạnh?