Trang 3 của 5 Đầu tiênĐầu tiên 12345 CuốiCuối
Kết quả 21 đến 30 của 49
  1. #21
    Ngày tham gia
    Mar 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ã:
    package javaapplication36;
     
    /**
    *
    * @author haitran
    */
    import java.util.scanner;
    public class javaapplication36 {
        public static void main(string[] args) {
            scanner in = new scanner(system.in);
            int n,i,j;
            string sx,tsv;
            system.out.println("số sinh viên cần nhập: ");
            n = in.nextint();
            in.nextline();
            string [] tensv = new string[n];
            for (i = 0; i < tensv.length; i++){
                system.out.println("tên sinh viên thứ " + (i + 1) + " là: " );
                tensv[i]= in.nextline();
            }
            system.out.println("sắp xếp lại tên sinh viên: ");
            for (i =0; i< tensv.length; i++){
              for (j= i+1; j <tensv.length; j++){
                  if (tensv[i].compareto(tensv[j])>0){
                      sx = tensv[i];
                      tensv[i] = tensv[j];
                      tensv[j] = sx;
                  }
              }
                system.out.println("tên sinh viên thứ " + (i + 1) + " là: ");
                system.out.println(tensv[i]);
            }
            system.out.println(" tên sinh viên cần tìm là: ");
            tsv = in.nextline();
            system.out.println("tên sinh viên vừa nhập là: " + tsv);
            int left = 0, right = n -1, mid, vt = -1;
            while (left < right){
                mid = (left + right)/2;
                if (tsv.equals(tensv[mid])){
                  vt = mid +1;
                }
                else if (tsv.compareto(tensv[mid]) > 0) {
                    left = mid +1;
                }
                else {
                    right =mid -1;
                    break;
                }
                if (mid > -1){
                    system.out.println("ten sv " + tsv + " o vi tri " + (mid +1) );
                    break;
                }
                else {
                    system.out.println("khong co sv can tim");
                    break;
                }
            }
            return ;
            }
        }
    </blockquote></div>
    </div>
    </div>
    không biết đúng hay sai, ai sửa giúp mình với

  2. #22
    Ngày tham gia
    Apr 2016
    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ã:
    package javaapplication36;
     
    /**
    *
    * @author haitran
    */
    import java.util.scanner;
    public class javaapplication36 {
        public static void main(string[] args) {
            scanner in = new scanner(system.in);
            int n,i,j;
            string sx,tsv;
            system.out.println("số sinh viên cần nhập: ");
            n = in.nextint();
            in.nextline();
            string [] tensv = new string[n];
            for (i = 0; i < tensv.length; i++){
                system.out.println("tên sinh viên thứ " + (i + 1) + " là: " );
                tensv[i]= in.nextline();
            }
            system.out.println("sắp xếp lại tên sinh viên: ");
            for (i =0; i< tensv.length; i++){
              for (j= i+1; j <tensv.length; j++){
                  if (tensv[i].compareto(tensv[j])>0){
                      sx = tensv[i];
                      tensv[i] = tensv[j];
                      tensv[j] = sx;
                  }
              }
                system.out.println("tên sinh viên thứ " + (i + 1) + " là: ");
                system.out.println(tensv[i]);
            }
            system.out.println(" tên sinh viên cần tìm là: ");
            tsv = in.nextline();
            system.out.println("tên sinh viên vừa nhập là: " + tsv);
            int left = 0, right = n -1, mid, vt = -1;
            while (left < right){
                mid = (left + right)/2;
                if (tsv.equals(tensv[mid])){
                  vt = mid +1;
                }
                else if (tsv.compareto(tensv[mid]) > 0) {
                    left = mid +1;
                }
                else {
                    right =mid -1;
                    break;
                }
                if (mid > -1){
                    system.out.println("ten sv " + tsv + " o vi tri " + (mid +1) );
                    break;
                }
                else {
                    system.out.println("khong co sv can tim");
                    break;
                }
            }
            return ;
            }
        }
    </blockquote></div>
    </div>
    </div>
    không biết đúng hay sai, ai sửa giúp mình với

  3. #23
    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ã:
    import java.util.scanner;
     
    public class bai02 {
        public static void main(string[]args){
            scanner in=new scanner(system.in);
            int n;
            system.out.println("so hoc sinh can nhap : ");
            n=in.nextint();
            in.nextline();
            system.out.println("nhap ds ho ten sv:");
            string []a=new string[n];
            int i;
            for(i=0;i<n;i++)
            {
                system.out.print("htsv thu "+i);
                a[i]=in.nextline();
            }
            // in ds
            system.out.println("danh sach htsv vua nhap:");
            for(i=0;i<n;i++)
            {
                system.out.println("htsv thu "+i+": "+a[i]);
            }
            //sap xep ds
            system.out.println("danh sach htsv sau khi sap xep:");
            string tmp;
            for(i=0;i<n-1;i++)
            {
                for(int j=i+1;j<n;j++)
                {
                    if(a[i].compareto(a[j])>0)
                    {
                        tmp=a[i];
                        a[i]=a[j];
                        a[j]=tmp;
                    }
                }
            }
            //in ra sau sap xep
            for(i=0;i<n;i++)
            {
                system.out.println(a[i]);
            }
            //nhap ten sv can tim
            string tsv;
            system.out.println("ten sv can tim:");
            tsv=in.nextline();
           
            //tim nhi phan
            int c=tim_nhi_phan(a,n,tsv);
            if(c==1){
                system.out.println(" tim thay hs nay");
            }
            else{
                system.out.println("khong thay hs nay trong ds");
            }
        }
        public static int tim_nhi_phan (string a[] , int n , string tsv)
        {
            int left = 0, right = n -1,mid;
            do
            {
                mid=(left+right)/2;
                if(tsv.compareto(a[mid])==0)
                {
                    system.out.print(" tai vi tri "+mid);
                    return 1;
                }
                else if(tsv.compareto(a[mid])<0)
                {
                    right=mid-1;   
                }
                else
                {
                    left=mid+1;
                }   
            }while(left<=right);
            return 0;
        }   
    }
    </blockquote></div>
    </div>
    </div>

  4. #24
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    Mã nguồn PHP:
    [color=#000000]
    sau gần 2 tuần vật vã với thời khóa biểu mới[/color][color=#007700]. [/color][color=#0000bb]cuối cùng cũng lập được một nhóm học java[/color][color=#007700]+[/color][color=#0000bb]android trong trường[/color][color=#007700]. [/color][color=#0000bb]phù[/color][color=#007700], [/color][color=#0000bb]chiến tiếp[/color][color=#007700]. [/color][color=#0000bb]hì[/color][color=#007700]...[/color] 
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

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


    Mã nguồn PHP:
    [color=#000000]
    package structure[/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]student1 [/color][color=#007700]{ private [/color][color=#0000bb]string name[/color][color=#007700][]; private [/color][color=#0000bb]int number[/color][color=#007700]; public [/color][color=#0000bb]void input[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"entry the value of variable number"[/color][color=#007700]); [/color][color=#0000bb]number [/color][color=#007700]= [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]in[/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 danh sach sinh vien"[/color][color=#007700]); [/color][color=#0000bb]name [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]number[/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]number[/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]"student: "[/color][color=#007700]+([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700])); [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } }[/color][color=#ff8000]//end the method input. [/color][color=#007700]public [/color][color=#0000bb]void output[/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]number[/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]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]"\t"[/color][color=#007700]); } }[/color][color=#ff8000]//end the method output. [/color][color=#007700]public [/color][color=#0000bb]void sort[/color][color=#007700](){ [/color][color=#0000bb]string temp[/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]number[/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]number[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++){ if( [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]])>[/color][color=#0000bb]0 [/color][color=#007700]){ [/color][color=#0000bb]temp [/color][color=#007700]= [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]temp[/color][color=#007700]; } } } }[/color][color=#ff8000]//end the method sort. [/color][color=#007700]public [/color][color=#0000bb]void shownumber[/color][color=#007700]([/color][color=#0000bb]string student[/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]number[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++){ if( [/color][color=#0000bb]student[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/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]"vi tri trong danh sach"[/color][color=#007700]+([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700])); break; } else if([/color][color=#0000bb]i[/color][color=#007700]==[/color][color=#0000bb]number[/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]"khong tim thay"[/color][color=#007700]); } } }[/color][color=#ff8000]//end the shownumber. [/color][color=#007700]public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string args [/color][color=#007700][]){ [/color][color=#0000bb]student1 out [/color][color=#007700]= new [/color][color=#0000bb]student1[/color][color=#007700](); [/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]input[/color][color=#007700](); [/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]output[/color][color=#007700](); [/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]sort[/color][color=#007700](); [/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]output[/color][color=#007700](); [/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]shownumber[/color][color=#007700]([/color][color=#dd0000]"ho hoai kiet"[/color][color=#007700]); }[/color][color=#ff8000]//end the method main. [/color][color=#007700]}[/color][color=#ff8000]//end the class student1.[/color] 
    </blockquote></div>
    </div>
    </div>

  5. #25
    Ngày tham gia
    Dec 2014
    Bài viết
    0
    ai giúp mình với sao ra được 189 vậy. chạy tay mãi mà không ra.
    <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]
    int sum1[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]int number1[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];while([/color][color=#0000bb]number1[/color][color=#007700]<[/color][color=#0000bb]20[/color][color=#007700]){ [/color][color=#0000bb]number1[/color][color=#007700]++; if([/color][color=#0000bb]number1[/color][color=#007700]==[/color][color=#0000bb]10 [/color][color=#007700]|| [/color][color=#0000bb]number1[/color][color=#007700]==[/color][color=#0000bb]11[/color][color=#007700]) continue; [/color][color=#0000bb]sum1[/color][color=#007700]+=[/color][color=#0000bb]number1[/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]"the sum is: "[/color][color=#007700]+[/color][color=#0000bb]sum1[/color][color=#007700]); [/color][color=#ff8000]//189[/color] 
    </blockquote></div>
    </div>
    </div>

  6. #26
    Ngày tham gia
    Apr 2016
    Bài viết
    0
    Trích dẫn Gửi bởi sky6596
    <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 template, choose tools | templates* and open the template in the editor.*/ [/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 sky*/[/color][color=#007700]public class [/color][color=#0000bb]student [/color][color=#007700]{ private [/color][color=#0000bb]string name[/color][color=#007700][]; private [/color][color=#0000bb]int numberstudent[/color][color=#007700]; public [/color][color=#0000bb]void input[/color][color=#007700]() { [/color][color=#0000bb]scanner inp [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/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 : "[/color][color=#007700]); [/color][color=#0000bb]numberstudent [/color][color=#007700]= [/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]inp[/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 cac sinh vien : "[/color][color=#007700]); [/color][color=#0000bb]name [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]numberstudent[/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]numberstudent[/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]"sinh vien thu : " [/color][color=#007700]+ ([/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700])); [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } } public [/color][color=#0000bb]void showlist[/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]numberstudent[/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]name[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]); } } public [/color][color=#0000bb]void sapxep[/color][color=#007700]() { for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]numberstudent[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]> [/color][color=#0000bb]0[/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]1[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++) { if ([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]]) > [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]string temp [/color][color=#007700]= [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]]; [/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]j [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]] = [/color][color=#0000bb]temp[/color][color=#007700]; } } } } public [/color][color=#0000bb]int search[/color][color=#007700]([/color][color=#0000bb]string hoten[/color][color=#007700]) { [/color][color=#0000bb]int d [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700], [/color][color=#0000bb]c [/color][color=#007700]= [/color][color=#0000bb]numberstudent [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700], [/color][color=#0000bb]g [/color][color=#007700]= -[/color][color=#0000bb]1[/color][color=#007700]; while ([/color][color=#0000bb]d [/color][color=#007700]<= [/color][color=#0000bb]c[/color][color=#007700]) { [/color][color=#0000bb]g [/color][color=#007700]= ([/color][color=#0000bb]d [/color][color=#007700]+ [/color][color=#0000bb]c[/color][color=#007700]) / [/color][color=#0000bb]2[/color][color=#007700]; if ([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]g[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]hoten[/color][color=#007700])) { return [/color][color=#0000bb]g [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; } if ([/color][color=#0000bb]hoten[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]name[/color][color=#007700][[/color][color=#0000bb]g[/color][color=#007700]]) > [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]c [/color][color=#007700]= [/color][color=#0000bb]g [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]; } else { [/color][color=#0000bb]d [/color][color=#007700]= [/color][color=#0000bb]g [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; } } return -[/color][color=#0000bb]1[/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]student st1 [/color][color=#007700]= new [/color][color=#0000bb]student[/color][color=#007700](); [/color][color=#0000bb]st1[/color][color=#007700].[/color][color=#0000bb]input[/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 sinh vien da nhap : "[/color][color=#007700]); [/color][color=#0000bb]st1[/color][color=#007700].[/color][color=#0000bb]showlist[/color][color=#007700](); [/color][color=#0000bb]st1[/color][color=#007700].[/color][color=#0000bb]sapxep[/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 lai la : "[/color][color=#007700]); [/color][color=#0000bb]st1[/color][color=#007700].[/color][color=#0000bb]showlist[/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 sinh vien can tim : "[/color][color=#007700]); [/color][color=#0000bb]scanner inp [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]string hoten [/color][color=#007700]= [/color][color=#0000bb]inp[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]int k [/color][color=#007700]= [/color][color=#0000bb]st1[/color][color=#007700].[/color][color=#0000bb]search[/color][color=#007700]([/color][color=#0000bb]hoten[/color][color=#007700]); if ([/color][color=#0000bb]k [/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]"so thu tu cua sinh vien do trong danh sach la : "[/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]k[/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 sinh vien vua nhap khong co trong danh sach"[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>
    bạn nói rõ về phương thức dưới được hk?
    public int search(string hoten) {

    int d = 0, c = numberstudent - 1, g = -1;
    while (
    d <= c) {
    g = (d + c) / 2;
    if (
    name[g].equals(hoten)) {
    return
    g + 1;
    }
    if (
    hoten.compareto(name[g]) > 0) {
    c = g - 1;
    } else {
    d = g + 1;
    }
    }
    return -
    1;
    }

  7. #27
    Ngày tham gia
    Mar 2014
    Bài viết
    0
    em xin nộp bài :d
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

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


    Mã:
    import java.util.scanner;
    public class bt1 {
        public static void main(string[] args)  {
            scanner input = new scanner(system.in);
            system.out.print("nhap so sinh vien: ");
            int n = input.nextint();
            input.nextline();
            string[] danhsachsv = new string[n];
            system.out.println("**nhap ten cac sinh vien**");
            for (int i=0; i<n; i++) {
                system.out.print("sinh vien " + (i+1) + ": ");
                danhsachsv[i] = input.nextline();
            }
            for (int i=0; i<n; i++) {
                for (int j=(i+1); j<n; j++) {
                    if (danhsachsv[i].compareto(danhsachsv[j]) > 0) {
                        string phu = danhsachsv[i];
                        danhsachsv[i] = danhsachsv[j];
                        danhsachsv[j] = phu;
                    }
                }
            }
            system.out.print("nhap ten sinh vien can tim so thu tu: ");
            string timsv = input.nextline();
            int phu = 0;
            for (int i=0; i<n; i++) {
                    if (danhsachsv[i].equals(timsv)) {
                        system.out.println("so thu tu cua " + timsv + " la " + (i+1));
                        phu = 1;
                        break;
                }
            }
            if (phu == 0) {
                system.out.println("khong co ten " + timsv + " trong danh sach.");
            }
        }
    }
    </blockquote></div>
    </div>
    </div>

  8. #28
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    mình nộp bài nhé (đã tham khảo 2 hàm so sánh của các bạn trước)
    <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]student[/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]){ [/color][color=#0000bb]scanner nhap [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]int n[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]printf[/color][color=#007700]([/color][color=#dd0000]"nhap so luong sinh vien: "[/color][color=#007700]); [/color][color=#0000bb]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 tensv[/color][color=#007700][] = new [/color][color=#0000bb]string[/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 ten sinh vien:"[/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]"sv " [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]": "[/color][color=#007700]); [/color][color=#0000bb]tensv[/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=#ff8000]// sap xep //string item; [/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]tensv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]) > [/color][color=#0000bb]0[/color][color=#007700]){ [/color][color=#0000bb]string item [/color][color=#007700]= [/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]item[/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 sv 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=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1 [/color][color=#007700]+[/color][color=#dd0000]". "[/color][color=#007700]+ [/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]); } [/color][color=#ff8000]//tim kiem [/color][color=#0000bb]string tim[/color][color=#007700]; [/color][color=#0000bb]int k [/color][color=#007700]= [/color][color=#0000bb]0[/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]tim [/color][color=#007700]= [/color][color=#0000bb]nhap[/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]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++){ if([/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]i[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"tim thay ten sinh vien "[/color][color=#007700]+[/color][color=#0000bb]tensv[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]); [/color][color=#0000bb]k [/color][color=#007700]+= [/color][color=#0000bb]1[/color][color=#007700]; } } if([/color][color=#0000bb]k[/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]"khong tim thay!!"[/color][color=#007700]); } } }[/color] 
    </blockquote></div>
    </div>
    </div>

  9. #29
    Ngày tham gia
    May 2014
    Bài viết
    0
    bài 1:
    <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 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 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]scanner input2 [/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]j[/color][color=#007700]; [/color][color=#0000bb]string v[/color][color=#007700]; [/color][color=#0000bb]int left[/color][color=#007700], [/color][color=#0000bb]right[/color][color=#007700], [/color][color=#0000bb]mid[/color][color=#007700]; [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]arrsinhvien [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]50[/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]n [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/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]"sinh vien " [/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]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]input2[/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]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]"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]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]); } [/color][color=#ff8000]// pp chen [/color][color=#007700]for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]1[/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]v [/color][color=#007700]= [/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]j [/color][color=#007700]= [/color][color=#0000bb]i[/color][color=#007700]; while ( ([/color][color=#0000bb]j[/color][color=#007700]> [/color][color=#0000bb]0[/color][color=#007700]) && ([/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]-[/color][color=#0000bb]1[/color][color=#007700]].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]v[/color][color=#007700])> [/color][color=#0000bb]0[/color][color=#007700]) ) { [/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]-[/color][color=#0000bb]1[/color][color=#007700]]; [/color][color=#0000bb]j[/color][color=#007700]--; } [/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]v[/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 sinh vien 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]"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]arrsinhvien[/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 sinh vien muon tim:"[/color][color=#007700]); [/color][color=#0000bb]v [/color][color=#007700]= [/color][color=#0000bb]input2[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#ff8000]//tìm kiếm nhị phân [/color][color=#0000bb]left [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]right [/color][color=#007700]= [/color][color=#0000bb]n[/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]) { [/color][color=#0000bb]mid [/color][color=#007700]= ([/color][color=#0000bb]left [/color][color=#007700]+ [/color][color=#0000bb]right[/color][color=#007700])/[/color][color=#0000bb]2[/color][color=#007700]; if ( [/color][color=#0000bb]v[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]mid[/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]"tim thay sinh vien co ten: " [/color][color=#007700]+ [/color][color=#0000bb]v [/color][color=#007700]+ [/color][color=#dd0000]" o vi tri: " [/color][color=#007700]+ [/color][color=#0000bb]mid[/color][color=#007700]); break; } else if ( [/color][color=#0000bb]v[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]mid[/color][color=#007700]])> [/color][color=#0000bb]0[/color][color=#007700]) [/color][color=#0000bb]left [/color][color=#007700]= [/color][color=#0000bb]mid [/color][color=#007700]+ [/color][color=#0000bb]1[/color][color=#007700]; else [/color][color=#0000bb]right [/color][color=#007700]= [/color][color=#0000bb]mid [/color][color=#007700]- [/color][color=#0000bb]1[/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]"không tim thay sinh vien: " [/color][color=#007700]+ [/color][color=#0000bb]v[/color][color=#007700]); }[/color] 
    </blockquote></div>
    </div>
    </div>

  10. #30
    Ngày tham gia
    Oct 2014
    Bài viết
    0
    nộp bài:


    Mã:
    package bai10;
     
    import java.util.scanner ;
     
    public class break_and_continue {
     
        public static void main (string[] args){
            /*------------------khai bao du lieu---------------------*/
            long begin = system.currenttimemillis();
            int i, j, n;
            scanner strnhap = new scanner (system.in);
            scanner intnhap = new scanner (system.in);
            system.out.print("nhap so luong sinh vien: ");
            n = intnhap.nextint();
           
            string [] strhoten = new string [n];
            for (i=0 ; i< n ; i++){
                system.out.print ("sinh vien thu "+(i+1)+ " : ");
                strhoten[i]= strnhap.nextline();
            }
            system.out.println ("-----danh sach sinh vien da nhap------");
            for (i=0 ; i< n ; i++){
                system.out.println ((i+1)+ ": " + strhoten[i]);
            }
            long end = system.currenttimemillis();
           
            system.out.print("--thoi gian thuc thi nhap du lieu-- : " + (end-begin) + "
    ");
            /*------------------khai bao du lieu---------------------*/
           
           
            /*------------------sap xep du lieu theo thu tu a,b,c---------------------*/
            long begin1 = system.currenttimemillis();
           
            for (i=0; i<n ; i++){
                for (j=i+1;j<n ; j++){
                    if (strhoten[i].comparetoignorecase(strhoten[j])>0){
                        string tam = strhoten[i];
                        strhoten[i] = strhoten[j];
                        strhoten[j] = tam ;
                    }
                }
            }
           
            system.out.println("---- danh sach sinh vien sau khi sap xep---");
            for (i=0 ; i< n ; i++)
                system.out.println ((i+1)+ ": " + strhoten[i]);
            long end1 = system.currenttimemillis();
            system.out.println("thoi gian thuc sap xep: " + (end1-begin1));
            /*------------------sap xep du lieu theo thu tu a,b,c---------------------*/
           
            /*tim kiem theo phuong phap nhi phan*/
            for (i = 0; i < n ; i++)
                system.out.println((i + 1) + " " + strhoten[i]);
            //search.
            system.out.print ("ten sinh vien can tim: ");
            string name = strnhap.nextline();
           
            int left=0 , right = n-1 , middle;
                do {
                    middle = (left+right)/2;
                    if (name.equals(strhoten[middle]))
                        break;
                    else
                    {
                        if (strhoten[middle].compareto(name) > 0 )
                            right = middle - 1;
                        else
                            left = middle + 1;
                    }
                } while (left <= right);
                if (left <= right)
                    system.out.println("sinh vien "+name+" o vi tri thu: " +(middle+1));
                else
                    system.out.println("khong ton tai") ;
               
            /*tim kiem theo phuong phap nhi phan*/
        }
    }
    có nghiên cứu phần compareto, pp nhị phân search tại : http://hus.edu.vn/thcs/bai5.html

Trang 3 của 5 Đầu tiênĐầu tiên 12345 CuốiCuối

Quyền viết bài

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