Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class TestStudent {
- int id;
- String name;
- public void insertInfo(String n,int i){
- name = n;
- id = i;
- }
- }
- public class Main{
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- TestStudent[] s=new TestStudent[5];
- for(int i=0;i<5;i++)
- {
- System.out.print("Enter the name of " + (i+1) + " student -> ");
- String name1 = sc.nextLine();
- System.out.print("Enter the id of " + (i+1) + " student -> ");
- int id1 = sc.nextInt();
- s[i].insertInfo(name1,id1);
- }
- for(int i=0;i<5;i++)
- {
- System.out.println("The name of " + (i+1) + " is" + s[i].name + " and id is " +s[i].id + ".");
- }
- }
- }
Add Comment
Please, Sign In to add comment