Java program to find various Colleges under every University | IT2305 - Java Programming Lab

AIM:
 To write a Java program to find various Colleges under every University in IT2305 - Java Programming Laboratory.

SOURCE CODE:
import java.util.*;
import java.lang.*;
class Univ
{
        String x[][];
        int n,m,i,j;
        public void getData()
        {
                Scanner sin=new Scanner(System.in);
                System.out.print("Enter the no of university:");
                n=sin.nextInt();
                x=new String[n][];
                for(i=0;i<x.length;i++)
                {
                        System.out.print("Enter the no of colleges under university"+(i+1)+":");
                        m=sin.nextInt();
                        x[i]=new String[m];
                }
                for(i=0;i<x.length;i++)
                {
                        System.out.println("Enter the college name under university"+(i+1)+":");
                 for(j=0;j<x[i].length;j++)
                                x[i][j]=sin.next();
                }
        }
        public void displayData()
        {
                System.out.println("*****************************************");
                System.out.println(Arrays.deepToString(x));
                System.out.println("*****************************************");
        }
}
public class UnivOperation
{
        public static void main(String args[])
        {
                Univ u1=new Univ();
                u1.getData();
                u1.displayData();
        }
}
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: