Guest User

Java Program

a guest
Jan 21st, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.*;
  2. class TestStudent {
  3.  
  4.     int id;
  5.     String name;
  6.  
  7.     public void insertInfo(String n,int i){
  8.         name = n;
  9.         id = i;
  10.     }
  11. }
  12. public class Main{
  13.     public static void main(String[] args){
  14.         Scanner sc = new Scanner(System.in);
  15.         TestStudent[] s=new TestStudent[5];
  16.         for(int i=0;i<5;i++)
  17.         {
  18.             System.out.print("Enter the name of " + (i+1) + " student -> ");
  19.             String name1 = sc.nextLine();
  20.             System.out.print("Enter the id of " + (i+1) + " student -> ");
  21.             int id1 = sc.nextInt();
  22.             s[i].insertInfo(name1,id1);
  23.         }
  24.         for(int i=0;i<5;i++)
  25.         {
  26.             System.out.println("The name of " + (i+1) + " is" + s[i].name + " and id is " +s[i].id + ".");
  27.         }
  28.     }
  29. }
Add Comment
Please, Sign In to add comment