01/10/2018, 09:21 
               
            Nhập dữ liệu từ bàn phím nhưng nhập xong vẫn báo null và 0
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GiuaMon;
import java.util.Scanner;
/**
 *
 * @author PLH
 */
public class Student {
    
    static String rollNo;
    static String name;
    static int age;
    static int score;
    static Scanner s = new Scanner(System.in);
    static int i=0;
    static void input(){
        
        for(i=0;i<5;i++){
            System.out.println("*************************");
            System.out.println("nhap thong tin hoc sinh:");
            System.out.print("RollNo: ");
            String rollNo = s.nextLine();
            System.out.print("Name: ");
            String name = s.nextLine();
            System.out.print("Age: ");
            int age = s.nextInt();
            System.out.print("score: ");
            int score = s.nextInt();s.nextLine();
        }
    }
    static void display(){
        System.out.printf("%-15s %-20s %-10s %-10s %n", "RollNo", "Name", "Age", "Score");
        for(i = 0; i < 5; i++){
            System.out.printf("%-15s %-20s %-10s %-10s %n", rollNo, name, age, score);
        }
    }
    public static void main(String[] args) {
        input();
        display();
    }
}
            Bài liên quan
         
                
            




Code tham khảo: Ở đây mình dùng ArrayList để quản lý, bạn thay bằng mảng cũng được.
mình cảm ơn bạn nhiều. cho mình thêm 1 tí là nếu đề bài yêu cầu mình viết method input() riêng biệt rồi khởi tạo 1 mảng 5 sinh viên trong hàm main và hiển thị ra thì phải làm thế nào