Trang 3 của 9 Đầu tiênĐầu tiên 12345 ... CuốiCuối
Kết quả 21 đến 30 của 85
  1. #21
    Ngày tham gia
    Aug 2014
    Bài viết
    0
    các bạn cho mình hỏi tí.trong bài 1 mình code như thế này thì ra đúng như hình 1.


    Mã nguồn PHP:
    [color=#000000]
    package baitap[/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]bai91 [/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 nhaplieu [/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]boolean kt [/color][color=#007700]= [/color][color=#0000bb]false[/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 số sinh viên : "[/color][color=#007700]); [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [[/color][color=#0000bb]color[/color][color=#007700]=[/color][color=#ff8000]#ff0000]nhaplieu.nextline();[/color] [/color][color=#0000bb]string arrhoten[/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]"nhập sinh viên thứ : " [/color][color=#007700]+ [/color][color=#0000bb]i[/color][color=#007700]); [/color][color=#0000bb]arrhoten[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]nhaplieu[/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]"nhập tên sinh viên muốn tìm : "[/color][color=#007700]); [/color][color=#0000bb]string xautim [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextline[/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]++) { if ([/color][color=#0000bb]xautim[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]arrhoten[/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]"có trong danh sách"[/color][color=#007700]); [/color][color=#0000bb]kt [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; } } if ([/color][color=#0000bb]kt [/color][color=#007700]== [/color][color=#0000bb]false[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]p2rintln[/color][color=#007700]([/color][color=#dd0000]"khong có trong danh sách"[/color][color=#007700]); } }}[/color] 
    còn nếu như xóa đi cái nhaplieu.nextline(); phía trên thì lại ra hình 2. không hiểu sao nó lại ra một lượt 2 dòng luôn

  2. #22
    Ngày tham gia
    Jul 2015
    Bài viết
    2
    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]
    package baitap[/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]bai1 [/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]int a[/color][color=#007700], [/color][color=#0000bb]i[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"so sinh vien: "[/color][color=#007700]); [/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]string arrstring[/color][color=#007700][] = new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]a[/color][color=#007700]]; if ([/color][color=#0000bb]a [/color][color=#007700]> [/color][color=#0000bb]0[/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]a[/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 sinh vien thu " [/color][color=#007700]+[/color][color=#0000bb]i[/color][color=#007700]); [/color][color=#0000bb]arrstring[/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]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]string ten [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]int x[/color][color=#007700]=[/color][color=#0000bb]0[/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]a[/color][color=#007700];[/color][color=#0000bb]i[/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] 
    </blockquote></div>
    </div>
    </div>

    bài 2:
    <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 baitap[/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]{ 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]int n[/color][color=#007700], [/color][color=#0000bb]k[/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]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 can nhap "[/color][color=#007700]); [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]int arrint[/color][color=#007700][] = new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]]; if([/color][color=#0000bb]n[/color][color=#007700]>[/color][color=#0000bb]0[/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]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]nhapdulieu[/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]"day so vua nhap la " [/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]arrint[/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](); 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]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] > [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]) { [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]k[/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 sau khi duoc sap xep la "[/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]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]" "[/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]"so phan tu nhap khong hop le"[/color][color=#007700]); }}[/color] 
    </blockquote></div>
    </div>
    </div>


    bài 3:
    <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 baitap[/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]bai3 [/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]int[/color][color=#007700][][] [/color][color=#0000bb]arrint1[/color][color=#007700]; [/color][color=#0000bb]int[/color][color=#007700][][] [/color][color=#0000bb]arrint2[/color][color=#007700]; [/color][color=#0000bb]int n[/color][color=#007700], [/color][color=#0000bb]m[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so hang "[/color][color=#007700]); [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap so cot "[/color][color=#007700]); [/color][color=#0000bb]m [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]arrint1 [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]][[/color][color=#0000bb]m[/color][color=#007700]]; [/color][color=#0000bb]arrint2 [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][[/color][color=#0000bb]n[/color][color=#007700]][[/color][color=#0000bb]m[/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 ma tran 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]n[/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]m[/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]"nhap phan tu hang " [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]" cot " [/color][color=#007700]+ [/color][color=#0000bb]j[/color][color=#007700]+[/color][color=#dd0000]" "[/color][color=#007700]); [/color][color=#0000bb]arrint1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]nhapdulieu[/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 ma tran 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]n[/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]m[/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]"nhap phan tu hang " [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]" cot " [/color][color=#007700]+ [/color][color=#0000bb]j[/color][color=#007700]+[/color][color=#dd0000]" "[/color][color=#007700]); [/color][color=#0000bb]arrint2[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]nhapdulieu[/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 tran 1 vua nhap "[/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]++) { 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]m[/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]arrint1[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"ma tran 2 vua nhap "[/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]++) { 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]m[/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]arrint2[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"tong 2 ma tran vua nhap la "[/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]++) { 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]m[/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]arrint1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]][[/color][color=#0000bb]j[/color][color=#007700]]+[/color][color=#0000bb]arrint2[/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] 
    </blockquote></div>
    </div>
    </div>

  3. #23
    Ngày tham gia
    Jul 2015
    Bài viết
    13
    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ã:
    int sosinhvien;
            scanner k = new scanner(system.in);
         
                system.out.println("mời bạn nhập số sinh viên: ");
                sosinhvien = k.nextint();
                k.nextline();
             
                string [] tensinhvien = new string[sosinhvien];
         
            for(int i=0; i<sosinhvien;i++)
            {
                system.out.println("bạn nhập tên sinh viên thứ " + (i+1) + " vào danh sách: ");
                tensinhvien[i] = k.nextline();
            }
     
            system.out.println("mời bạn nhập tên sinh viên muốn tìm kiếm: ");
            string sinhvien = k.nextline();
            system.out.println(sinhvien);
            for(int i=0; i<sosinhvien;i++)
            {
                if(sinhvien.equals(tensinhvien[i]))
                    system.out.println("sinh viên này có trong danh sách");
                else
                    system.out.println("sinh viên này không có trong danh sách");
            }
    </blockquote></div>
    </div>
    </div>
    bài 2:
    <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ã:
    int soluong;
            scanner k = new scanner(system.in);
            int a=3,b=5;
                system.out.println("có bao nhiêu số trong dãy số này: ");
                soluong = k.nextint();
                int [] mangso = new int[soluong];
                for(int i=0;i<soluong;i++)
                {
                    system.out.println("mời bạn nhập giá trị phần tử thứ "+ (i+1) +" vào: ");
                    mangso[i]=k.nextint();
                }
               
                int temp;
               
                for (int i=0; i<soluong-1; i++)
                    for (int j=soluong-1;j>i;j--)
                        if (mangso[j] < mangso[j-1])
                        {
                            temp = mangso[j];
                            mangso[j] = mangso[j-1];
                            mangso[j-1]=temp;
                        }
                   
                system.out.println("các phần tử sau khi được sắp xếp là:");
                for(int i=0;i<soluong;i++)
                {
                    system.out.println(mangso[i]);
                }
    </blockquote></div>
    </div>
    </div>

  4. #24
    Ngày tham gia
    Jul 2015
    Bài viết
    0
    thanhks

  5. #25
    Ngày tham gia
    Apr 2015
    Bài viết
    0
    Trích dẫn Gửi bởi phongdt
    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]
    package 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];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]inputmismatchexception[/color][color=#007700]; public class [/color][color=#0000bb]arrayofstudents [/color][color=#007700]{ private [/color][color=#0000bb]int numberofstudents[/color][color=#007700];private [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]name[/color][color=#007700];private static [/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]); public [/color][color=#0000bb]arrayofstudents[/color][color=#007700](){[/color][color=#0000bb]boolean continueloop [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700];[/color][color=#0000bb]int temp [/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]"enter number of students: " [/color][color=#007700]); while ( [/color][color=#0000bb]continueloop [/color][color=#007700]){try{[/color][color=#0000bb]temp [/color][color=#007700]= [/color][color=#0000bb]integer[/color][color=#007700].[/color][color=#0000bb]parseint[/color][color=#007700]( [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]() );if ( [/color][color=#0000bb]temp [/color][color=#007700]< [/color][color=#0000bb]0 [/color][color=#007700])throw new [/color][color=#0000bb]illegalargumentexception[/color][color=#007700]();else[/color][color=#0000bb]continueloop [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700];}catch( [/color][color=#0000bb]inputmismatchexception [/color][color=#007700]| [/color][color=#0000bb]illegalargumentexception e [/color][color=#007700]){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#dd0000]"please enter again!" [/color][color=#007700]);}} [/color][color=#0000bb]numberofstudents [/color][color=#007700]= [/color][color=#0000bb]temp[/color][color=#007700];[/color][color=#0000bb]name [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][ [/color][color=#0000bb]numberofstudents [/color][color=#007700]]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"enter name of each 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]numberofstudents[/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]printf[/color][color=#007700]( [/color][color=#dd0000]"%s %d\t"[/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]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();}} public [/color][color=#0000bb]void run[/color][color=#007700](){[/color][color=#0000bb]string str [/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]"find a student with his name"[/color][color=#007700]);while( [/color][color=#0000bb]true [/color][color=#007700]){while( [/color][color=#0000bb]str [/color][color=#007700]== [/color][color=#dd0000]"" [/color][color=#007700]){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#dd0000]"please enter a name: " [/color][color=#007700]);[/color][color=#0000bb]str [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();} [/color][color=#0000bb]int position [/color][color=#007700]= [/color][color=#0000bb]search[/color][color=#007700]( [/color][color=#0000bb]str [/color][color=#007700]);if ( [/color][color=#0000bb]position [/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]"found at position " [/color][color=#007700]+ ( [/color][color=#0000bb]position [/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]"not found!" [/color][color=#007700]); [/color][color=#ff8000]//ask user to continue or not?[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#dd0000]"do yout want to find an other student? enter y for new search" [/color][color=#007700]+[/color][color=#dd0000]" or an other button for ending"[/color][color=#007700]);[/color][color=#0000bb]string temp [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();if ( [/color][color=#0000bb]temp[/color][color=#007700].[/color][color=#0000bb]charat[/color][color=#007700]( [/color][color=#0000bb]0 [/color][color=#007700]) != [/color][color=#dd0000]'y' [/color][color=#007700])[/color][color=#0000bb]system[/color][color=#007700].exit( [/color][color=#0000bb]0 [/color][color=#007700]);else[/color][color=#0000bb]str [/color][color=#007700]= [/color][color=#dd0000]""[/color][color=#007700];}} private [/color][color=#0000bb]int search[/color][color=#007700]( [/color][color=#0000bb]string str [/color][color=#007700]){[/color][color=#0000bb]int counter [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700];while ( [/color][color=#0000bb]counter [/color][color=#007700]< [/color][color=#0000bb]numberofstudents [/color][color=#007700]){if ( [/color][color=#0000bb]str[/color][color=#007700].[/color][color=#0000bb]equalsignorecase[/color][color=#007700]( [/color][color=#0000bb]name[/color][color=#007700][ [/color][color=#0000bb]counter [/color][color=#007700]] ) )return [/color][color=#0000bb]counter[/color][color=#007700];else[/color][color=#0000bb]counter[/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]arrayofstudents newtest [/color][color=#007700]= new [/color][color=#0000bb]arrayofstudents[/color][color=#007700]();[/color][color=#0000bb]newtest[/color][color=#007700].[/color][color=#0000bb]run[/color][color=#007700]();} }[/color] 
    </blockquote></div>
    </div>
    </div>

    bài 2: chưa nhớ lắm các cách sắp xếp khác nên tạm thời để đấy. có gì mình sửa lại sau
    <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 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]; public class [/color][color=#0000bb]sortingarray [/color][color=#007700]{ private static final [/color][color=#0000bb]int[/color][color=#007700][] [/color][color=#0000bb]unsorted [/color][color=#007700]= { [/color][color=#0000bb]6[/color][color=#007700], [/color][color=#0000bb]4[/color][color=#007700], [/color][color=#0000bb]2[/color][color=#007700], [/color][color=#0000bb]1[/color][color=#007700], [/color][color=#0000bb]6[/color][color=#007700], [/color][color=#0000bb]3[/color][color=#007700], [/color][color=#0000bb]12[/color][color=#007700], [/color][color=#0000bb]10[/color][color=#007700], [/color][color=#0000bb]7[/color][color=#007700], [/color][color=#0000bb]9[/color][color=#007700], [/color][color=#0000bb]5[/color][color=#007700], [/color][color=#0000bb]3 [/color][color=#007700]};private [/color][color=#0000bb]int[/color][color=#007700][] [/color][color=#0000bb]sorted[/color][color=#007700];private [/color][color=#0000bb]int length[/color][color=#007700]; [/color][color=#ff8000]// constructor[/color][color=#007700]public [/color][color=#0000bb]sortingarray[/color][color=#007700](){[/color][color=#0000bb]length [/color][color=#007700]= [/color][color=#0000bb]unsorted[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700];[/color][color=#0000bb]sorted [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][ [/color][color=#0000bb]length [/color][color=#007700]];} [/color][color=#ff8000]// print array after sorting ( mac du ket qua giong nhau =)) )[/color][color=#007700]public [/color][color=#0000bb]void display[/color][color=#007700]( [/color][color=#0000bb]string str [/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]"
    array after " [/color][color=#007700]+ [/color][color=#0000bb]str [/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]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].[/color][color=#0000bb]printf[/color][color=#007700]( [/color][color=#dd0000]"%d "[/color][color=#007700], [/color][color=#0000bb]sorted[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]] );}} [/color][color=#ff8000]// bubble sorting[/color][color=#007700]public [/color][color=#0000bb]int[/color][color=#007700][] [/color][color=#0000bb]bubblesort[/color][color=#007700](){[/color][color=#0000bb]int[/color][color=#007700][] [/color][color=#0000bb]temp [/color][color=#007700]= [/color][color=#0000bb]arrays[/color][color=#007700].[/color][color=#0000bb]copyof[/color][color=#007700]( [/color][color=#0000bb]unsorted [/color][color=#007700], [/color][color=#0000bb]length [/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]length [/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]length[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++ ){if ( [/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]] > [/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]j [/color][color=#007700]] ){[/color][color=#0000bb]int value [/color][color=#007700]= [/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]];[/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]] = [/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]j [/color][color=#007700]];[/color][color=#0000bb]temp[/color][color=#007700][ [/color][color=#0000bb]j[/color][color=#007700]] = [/color][color=#0000bb]value[/color][color=#007700];}} return [/color][color=#0000bb]temp[/color][color=#007700];} [/color][color=#ff8000]// insertion sort//public int[] insertionsort()//{ //} [/color][color=#007700]public [/color][color=#0000bb]void run[/color][color=#007700](){[/color][color=#0000bb]sorted [/color][color=#007700]= [/color][color=#0000bb]bubblesort[/color][color=#007700]();[/color][color=#0000bb]display[/color][color=#007700]( [/color][color=#dd0000]"bubble sort" [/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]sortingarray newtest [/color][color=#007700]= new [/color][color=#0000bb]sortingarray[/color][color=#007700]();[/color][color=#0000bb]newtest[/color][color=#007700].[/color][color=#0000bb]run[/color][color=#007700]();} }[/color] 
    </blockquote></div>
    </div>
    </div>

    bài 3 :d

    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

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


    Mã nguồn PHP:
    [color=#000000]
    package 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]sumofmatrices [/color][color=#007700]{ private static [/color][color=#0000bb]scanner scanner [/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 class [/color][color=#0000bb]matrix [/color][color=#007700]{ private [/color][color=#0000bb]int[/color][color=#007700][][] [/color][color=#0000bb]matrix[/color][color=#007700]; private [/color][color=#0000bb]int row[/color][color=#007700]; private [/color][color=#0000bb]int column[/color][color=#007700]; [/color][color=#ff8000]// constructor [/color][color=#007700]public [/color][color=#0000bb]matrix[/color][color=#007700]() { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#dd0000]"enter number of row and column
    " [/color][color=#007700]); [/color][color=#0000bb]boolean continueloop [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; while( [/color][color=#0000bb]continueloop [/color][color=#007700]) { try { [/color][color=#0000bb]row [/color][color=#007700]= [/color][color=#0000bb]inputhandling[/color][color=#007700]( [/color][color=#dd0000]"row" [/color][color=#007700]); [/color][color=#0000bb]column [/color][color=#007700]= [/color][color=#0000bb]inputhandling[/color][color=#007700]( [/color][color=#dd0000]"column" [/color][color=#007700]); if ( [/color][color=#0000bb]row [/color][color=#007700]<= [/color][color=#0000bb]0 [/color][color=#007700]|| [/color][color=#0000bb]column [/color][color=#007700]<= [/color][color=#0000bb]0 [/color][color=#007700]) throw new [/color][color=#0000bb]illegalargumentexception[/color][color=#007700]( [/color][color=#dd0000]"row or column cannot have negative value" [/color][color=#007700]); else [/color][color=#0000bb]continueloop [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700]; } catch ( [/color][color=#0000bb]exception e [/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]( [/color][color=#0000bb]e [/color][color=#007700]); } } [/color][color=#0000bb]matrix [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][ [/color][color=#0000bb]row [/color][color=#007700]][ [/color][color=#0000bb]column [/color][color=#007700]]; } [/color][color=#ff8000]// constructor with argument [/color][color=#007700]public [/color][color=#0000bb]matrix[/color][color=#007700]( [/color][color=#0000bb]int row[/color][color=#007700], [/color][color=#0000bb]int column [/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]row [/color][color=#007700]= [/color][color=#0000bb]row[/color][color=#007700]; [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]column [/color][color=#007700]= [/color][color=#0000bb]column[/color][color=#007700]; [/color][color=#0000bb]matrix [/color][color=#007700]= new [/color][color=#0000bb]int[/color][color=#007700][ [/color][color=#0000bb]row [/color][color=#007700]][ [/color][color=#0000bb]column [/color][color=#007700]]; } public [/color][color=#0000bb]int getrow[/color][color=#007700]() { return [/color][color=#0000bb]row[/color][color=#007700]; } public [/color][color=#0000bb]int getcolumn[/color][color=#007700]() { return [/color][color=#0000bb]column[/color][color=#007700]; } [/color][color=#ff8000]// enter value of each elements of matrix [/color][color=#007700]public [/color][color=#0000bb]void passingvalue[/color][color=#007700]() { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#dd0000]"enter value for each element of matrix
    " [/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]row[/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]column[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++ ) { [/color][color=#0000bb]matrix[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]][ [/color][color=#0000bb]j [/color][color=#007700]] = [/color][color=#0000bb]inputhandling[/color][color=#007700]( [/color][color=#dd0000]"[" [/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]); } } public [/color][color=#0000bb]void display[/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]row[/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]column[/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]printf[/color][color=#007700]( [/color][color=#dd0000]"%d "[/color][color=#007700], [/color][color=#0000bb]matrix[/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=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700](); } } [/color][color=#ff8000]// ensure the entered value is a integer [/color][color=#007700]private static [/color][color=#0000bb]int inputhandling[/color][color=#007700]( [/color][color=#0000bb]string str [/color][color=#007700]) { [/color][color=#0000bb]boolean continueloop [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; [/color][color=#0000bb]int result [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; while( [/color][color=#0000bb]continueloop [/color][color=#007700]) { try { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print( [/color][color=#0000bb]str [/color][color=#007700]+ [/color][color=#dd0000]":\t" [/color][color=#007700]); [/color][color=#0000bb]result [/color][color=#007700]= [/color][color=#0000bb]integer[/color][color=#007700].[/color][color=#0000bb]parseint[/color][color=#007700]( [/color][color=#0000bb]scanner[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]() ); [/color][color=#0000bb]continueloop [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700]; } catch ( [/color][color=#0000bb]exception e [/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]( [/color][color=#dd0000]"value is invalid! please enter again" [/color][color=#007700]); } } return [/color][color=#0000bb]result[/color][color=#007700]; } [/color][color=#ff8000]// method to plus two matrices [/color][color=#007700]public static [/color][color=#0000bb]matrix addition[/color][color=#007700]( [/color][color=#0000bb]sumofmatrices temp[/color][color=#007700], [/color][color=#0000bb]matrix ma1[/color][color=#007700], [/color][color=#0000bb]matrix ma2 [/color][color=#007700]) [/color][color=#0000bb]throws exception [/color][color=#007700]{ if ( [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]row [/color][color=#007700]!= [/color][color=#0000bb]ma2[/color][color=#007700].[/color][color=#0000bb]row [/color][color=#007700]|| [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]column [/color][color=#007700]!= [/color][color=#0000bb]ma2[/color][color=#007700].[/color][color=#0000bb]column [/color][color=#007700]) { throw new [/color][color=#0000bb]exception[/color][color=#007700]( [/color][color=#dd0000]"rows or column of two matrices aren't equal. operation plus cannot be processed." [/color][color=#007700]); } else { [/color][color=#0000bb]int numberofrow [/color][color=#007700]= [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]row[/color][color=#007700], [/color][color=#0000bb]numberofcolumn [/color][color=#007700]= [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]column[/color][color=#007700]; [/color][color=#0000bb]matrix result [/color][color=#007700]= [/color][color=#0000bb]temp[/color][color=#007700].new [/color][color=#0000bb]matrix[/color][color=#007700]( [/color][color=#0000bb]numberofrow[/color][color=#007700], [/color][color=#0000bb]numberofcolumn [/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]numberofrow[/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]numberofcolumn[/color][color=#007700]; [/color][color=#0000bb]j[/color][color=#007700]++ ) { [/color][color=#0000bb]result[/color][color=#007700].[/color][color=#0000bb]matrix[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]][ [/color][color=#0000bb]j [/color][color=#007700]] = [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]matrix[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]][ [/color][color=#0000bb]j [/color][color=#007700]] + [/color][color=#0000bb]ma2[/color][color=#007700].[/color][color=#0000bb]matrix[/color][color=#007700][ [/color][color=#0000bb]i [/color][color=#007700]][ [/color][color=#0000bb]j [/color][color=#007700]]; } return [/color][color=#0000bb]result[/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]sumofmatrices newtest [/color][color=#007700]= new [/color][color=#0000bb]sumofmatrices[/color][color=#007700](); [/color][color=#0000bb]matrix ma1 [/color][color=#007700]= [/color][color=#0000bb]newtest[/color][color=#007700].new [/color][color=#0000bb]matrix[/color][color=#007700](); [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]passingvalue[/color][color=#007700](); [/color][color=#0000bb]ma1[/color][color=#007700].[/color][color=#0000bb]display[/color][color=#007700](); [/color][color=#0000bb]matrix ma2 [/color][color=#007700]= [/color][color=#0000bb]newtest[/color][color=#007700].new [/color][color=#0000bb]matrix[/color][color=#007700](); [/color][color=#0000bb]ma2[/color][color=#007700].[/color][color=#0000bb]passingvalue[/color][color=#007700](); [/color][color=#0000bb]ma2[/color][color=#007700].[/color][color=#0000bb]display[/color][color=#007700](); [/color][color=#0000bb]matrix ma3[/color][color=#007700]; try { [/color][color=#0000bb]ma3 [/color][color=#007700]= [/color][color=#0000bb]addition[/color][color=#007700]( [/color][color=#0000bb]newtest[/color][color=#007700], [/color][color=#0000bb]ma1[/color][color=#007700], [/color][color=#0000bb]ma2 [/color][color=#007700]); [/color][color=#0000bb]ma3[/color][color=#007700].[/color][color=#0000bb]display[/color][color=#007700](); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]err[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]( [/color][color=#0000bb]e [/color][color=#007700]); } } }[/color] 
    </blockquote></div>
    </div>
    </div>
    bạn ơi bài bạn dùng nhiều cấu trúc lạ quá, tớ không hiểu lắm hjx

  6. #26
    Ngày tham gia
    Jan 2015
    Bài viết
    0
    mọi người ơi, xem hộ mình bài 1 này sai chỗ nào với, mình tìm mãi không ra hjc
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>

    show spoiler
    hide spoiler

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


    Mã nguồn PHP:
    [color=#000000]
    [/color][color=#007700]public class [/color][color=#0000bb]bai9 [/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=#ff8000]// todo code application logic here [/color][color=#0000bb]sinhvien sv [/color][color=#007700]= new [/color][color=#0000bb]sinhvien[/color][color=#007700](); [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]nhap[/color][color=#007700](); if([/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]search[/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]"không có tên này trong mảng"[/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]"có tên sinh viên này trong mảng"[/color][color=#007700]); }} public class [/color][color=#0000bb]sinhvien [/color][color=#007700]{ private [/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]sinhvien [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; private [/color][color=#0000bb]int n[/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]); public [/color][color=#0000bb]void nhap[/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 vào số sinh viên: "[/color][color=#007700]); [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]sinhvien [/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]"nhập vào tên sinh viên: "[/color][color=#007700]); [/color][color=#0000bb]sinhvien[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } } public [/color][color=#0000bb]boolean search[/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 vào tên sinh viên muốn tìm kiếm: "[/color][color=#007700]); [/color][color=#0000bb]string data [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]boolean kq [/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]n[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if([/color][color=#0000bb]sinhvien[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]data[/color][color=#007700])) [/color][color=#0000bb]kq [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; } return [/color][color=#0000bb]kq[/color][color=#007700]; }}[/color] 
    </blockquote></div>
    </div>
    </div>

  7. #27
    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=#ff8000]/** to change this template, choose tools | templates* and open the template in the editor.*/[/color][color=#0000bb]package edu[/color][color=#007700].[/color][color=#0000bb]buidu[/color][color=#007700].[/color][color=#0000bb]java[/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 buidu_sse*/[/color][color=#007700]public class array { 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]int a[/color][color=#007700]; [/color][color=#0000bb]int j [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]string ten[/color][color=#007700]; [/color][color=#0000bb]scanner nhaplieu [/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]"nhập vào số lượng hs: "[/color][color=#007700]); [/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]string arrint1[/color][color=#007700][]; [/color][color=#0000bb]arrint1 [/color][color=#007700]= new [/color][color=#0000bb]string[/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]arrint1[/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]"nhập tên hs thứ " [/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]arrint1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]next[/color][color=#007700](); } [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhập tên hs cần tìm: "[/color][color=#007700]); [/color][color=#0000bb]ten [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]next[/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]arrint1[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]arrint1[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]ten[/color][color=#007700])) { [/color][color=#0000bb]j[/color][color=#007700]++; } } if ([/color][color=#0000bb]j [/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]"không tìm thấy hs tên "[/color][color=#007700]+[/color][color=#0000bb]ten[/color][color=#007700]+[/color][color=#dd0000]" trong danh sách"[/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]"tìm thấy "[/color][color=#007700]+[/color][color=#0000bb]j[/color][color=#007700]+ [/color][color=#dd0000]" hs tên "[/color][color=#007700]+[/color][color=#0000bb]ten[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>
    bài 2
    <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ã:
    /*
    * to change this template, choose tools | templates
    * and open the template in the editor.
    */
    package edu.buidu.java;
     
    import java.util.scanner;
     
    /**
    *
    * @author buidu_sse
    */
    public class array {
     
        public static void main(string[] args) {
            int n;
            int tg;
            scanner nhaplieu = new scanner(system.in);
            system.out.println("dãy gồm mấy chữ số: ");
            n = nhaplieu.nextint();
            int[] arrint = new int[n];
            for(int i=0;i<arrint.length;i++){
                system.out.print("nhập vào số thứ "+(i+1)+": ");
                arrint[i]=nhaplieu.nextint();
            }
            for (int i = 0; i< arrint.length-1; i++) {
                for (int j =i+1; j < arrint.length; j++) {
                    if (arrint[j] < arrint[i]) {
                        tg = arrint[j];
                        arrint[j] = arrint[i];
                        arrint[i] = tg;
                    }
                }
            }
            system.out.println("day sau khi sx tang dan");
            for(int i=0;i<arrint.length;i++){
                system.out.print(arrint[i]);
                system.out.print(" ");
            }
            system.out.println("");
        }
    }
    </blockquote></div>
    </div>
    </div>
    bài 3
    <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>

    </blockquote></div>
    </div>
    </div>

  8. #28
    Ngày tham gia
    Sep 2014
    Bài viết
    0
    nhờ các bác giúp đỡ với ạ. em làm bài tập 1 với mã như sau:

    <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 array { private static [/color][color=#0000bb]scanner nhapdulieu[/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]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]string [/color][color=#007700][] [/color][color=#0000bb]arrsinhvien[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"số lượng sinh viên? "[/color][color=#007700]); [/color][color=#ff8000]//khai báo độ lớn của mảng từ số liệu nhập vào[/color][color=#0000bb]arrsinhvien [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700][[/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]()];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"số lượng sinh viên là " [/color][color=#007700]+ [/color][color=#0000bb]arrsinhvien[/color][color=#007700].[/color][color=#0000bb]length[/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:"[/color][color=#007700]); [/color][color=#ff8000]//vòng lặp để nhập tên sv[/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]arrsinhvien[/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]"sv" [/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]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();} [/color][color=#ff8000]//lấy tên sv theo stt[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"bạn muốn tìm sv có stt nào? "[/color][color=#007700]);[/color][color=#0000bb]int stt [/color][color=#007700]= [/color][color=#0000bb]nhapdulieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700]();[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"sinh viên stt " [/color][color=#007700]+ [/color][color=#0000bb]stt [/color][color=#007700]+ [/color][color=#dd0000]" có tên là " [/color][color=#007700]+ [/color][color=#0000bb]arrsinhvien[/color][color=#007700][[/color][color=#0000bb]stt [/color][color=#007700]- [/color][color=#0000bb]1[/color][color=#007700]]); }}[/color] 
    </blockquote></div>
    </div>
    </div>

    nhưng mà lúc chạy console thì nó không dừng lại ở sv1 cho em nhập tên mà nhảy luôn qua sv2. lỗi này không biết là do đâu. mong anh em chỉ giáo ạ.



    Mã nguồn PHP:
    [color=#000000]
    số lượng sinh viên[/color][color=#007700]? [/color][color=#0000bb]4số lượng sinh viên là 4nhập tên sinh viên[/color][color=#007700]:[/color][color=#0000bb]sv1[/color][color=#007700]: [/color][color=#0000bb]sv2[/color][color=#007700]: [/color][color=#0000bb]bsv3[/color][color=#007700]: [/color][color=#0000bb]csv4[/color][color=#007700]: [/color][color=#0000bb]dbạn muốn tìm sv có stt nào[/color][color=#007700]? [/color][color=#0000bb]3sinh viên stt 3 có tên là c[/color] 

  9. #29
    Ngày tham gia
    Feb 2015
    Bài viết
    0
    em làm thế này mà nó không xếp được mong các bác giúp đỡ..


    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]int n[/color][color=#007700],[/color][color=#0000bb]tg[/color][color=#007700]; [/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]int arrint[/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 n la:"[/color][color=#007700]); [/color][color=#0000bb]n[/color][color=#007700]=[/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]arrint[/color][color=#007700]=new [/color][color=#0000bb]int[/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]++) { [/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]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]=[/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); } [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"so moi nhap la:"[/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]++) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]" "[/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]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]j[/color][color=#007700]++) { if([/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]<[/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]) { [/color][color=#0000bb]tg[/color][color=#007700]=[/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]; [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]=[/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]; [/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]j[/color][color=#007700]]=[/color][color=#0000bb]tg[/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]"mnag xep theo thu tu tang dan la:"[/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]++) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]arrint[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]+[/color][color=#dd0000]" "[/color][color=#007700]); } }}[/color] 

  10. #30
    Ngày tham gia
    Apr 2014
    Bài viết
    0
    Trích dẫn Gửi bởi somedayiws
    các bạn cho mình hỏi tí.trong bài 1 mình code như thế này thì ra đúng như hình 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]
    package baitap[/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]bai91 [/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 nhaplieu [/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]boolean kt [/color][color=#007700]= [/color][color=#0000bb]false[/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 số sinh viên : "[/color][color=#007700]); [/color][color=#0000bb]n [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [[/color][color=#0000bb]color[/color][color=#007700]=[/color][color=#ff8000]#ff0000]nhaplieu.nextline();[/color] [/color][color=#0000bb]string arrhoten[/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]"nhập sinh viên thứ : " [/color][color=#007700]+ [/color][color=#0000bb]i[/color][color=#007700]); [/color][color=#0000bb]arrhoten[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]] = [/color][color=#0000bb]nhaplieu[/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]"nhập tên sinh viên muốn tìm : "[/color][color=#007700]); [/color][color=#0000bb]string xautim [/color][color=#007700]= [/color][color=#0000bb]nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextline[/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]++) { if ([/color][color=#0000bb]xautim[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#0000bb]arrhoten[/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]"có trong danh sách"[/color][color=#007700]); [/color][color=#0000bb]kt [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; } } if ([/color][color=#0000bb]kt [/color][color=#007700]== [/color][color=#0000bb]false[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]p2rintln[/color][color=#007700]([/color][color=#dd0000]"khong có trong danh sách"[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>
    còn nếu như xóa đi cái nhaplieu.nextline(); phía trên thì lại ra hình 2. không hiểu sao nó lại ra một lượt 2 dòng luôn
    Mã nguồn PHP:
    [color=#000000]
    sau khi nhập xong số sinh viên n[/color][color=#007700]=[/color][color=#0000bb]4 [/color][color=#007700]([/color][color=#0000bb]giả sử n[/color][color=#007700]=[/color][color=#0000bb]4[/color][color=#007700]) [/color][color=#0000bb]thì cònthừa 1 ký tự [/color][color=#dd0000]"enter"[/color][color=#007700]. [/color][color=#0000bb]tức là bạn nhập n[/color][color=#007700]=[/color][color=#0000bb]4 thì bạn nhấnphím enter để sang lệnh thao tác khác[/color][color=#007700]. [/color][color=#0000bb]đó là lý [/color][color=#007700]do [/color][color=#0000bb]nóxuất hiện 1 lần 2 dòng[/color][color=#007700]. [/color][color=#0000bb]và cũng vì câu lệnh tiếp theocủa bạn đọc vào 1 string nên lệnh nào sẽ đọc mặc đinh [/color][color=#dd0000]"enter"[/color][color=#0000bb]vào string đó[/color][color=#007700]. [/color][color=#0000bb]cho nên ở dòng đầu thấy trống không[/color][color=#007700].[/color][color=#0000bb]giải quyết[/color][color=#007700]: [/color][color=#0000bb]bạn nên thêm dòng nhaplieu[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]() [/color][color=#0000bb]sau khinhập số sinh viên[/color][color=#007700]. [/color][color=#0000bb]nó sẽ xóa đi ký tự enter thừa của bạn đấy[/color][color=#007700].[/color] 

Trang 3 của 9 Đầ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
  •