MihiCherub

Well-known member
  • Sep 14, 2009
    18,849
    1
    9,594
    113
    Gampaha
    1. Write a program that accepts ID, Name, E-mail address and Contact No. of all the students in a class and saves them in an array. Ask the user for the size of the class and the student details.


    Meka iwara karanna help ekak dendoooooooooooo
    pahala tiyenne mama liwwa programme eka


    .....................................................................................................................
    import javax.swing.*;

    public class ClassReg{

    public static void main(String[] args){

    String classsize=JOptionPane.showInputDialog("Enter the number of students in the class?");

    int students=Integer.parseInt(classsize);

    int[] stid=new int[students];
    String[] stname=new String[students];
    String[] stphone=new String[students];
    String[] stemail=new String[students];

    for(int i=0;i<students;i++){

    String studentid=JOptionPane.showInputDialog("Enter ID of the student "+ (i+1));

    int idno=Integer.parseInt(studentid);

    stid=idno;


    String studentname=JOptionPane.showInputDialog("Enter NAME of the student "+ (i+1));

    stname=studentname;


    String studentphone=JOptionPane.showInputDialog("Enter contact number of the student "+ (i+1));

    stphone=studentphone;

    String studentmail=JOptionPane.showInputDialog("Enter the Email address of the student?"+ (i+1));

    stemail=studentmail;


    system.out.println("student id is "+idno +", " +" student name is "+stname+""+" phoneno is"+stphone+","+"email address is"+stemail);


    }

    }

    }

    මචන් ඇයි මේ Swing අරන්.. අනිත් එක Joptionpanes දාල තියෙන්නේ?? උබට ඕනෙ swing එක්ක නම් ඔය ක්‍රමේ සාර්ථක මදි මචන්. util.scanner එකෙන් බැරිද?
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,849
    1
    9,594
    113
    Gampaha
    1. Write a program that accepts ID, Name, E-mail address and Contact No. of all the students in a class and saves them in an array. Ask the user for the size of the class and the student details.
    import java.util.Scanner;

    class A{
    static int size;

    public static void main (String [] Mihi){

    Scanner Sc = new Scanner(System.in);
    System.out.print("\nEnter the number of students in the class: ");
    size = Sc.nextInt();

    int[] stid = new int[size];
    String[] stname = new String[size];
    String[] stphone = new String[size];
    String[] stemail = new String[size];

    for(int i=0; i<size; i++){

    System.out.print("\nEnter ID of the student: ");
    stid = Sc.nextInt();

    System.out.print("\nEnter Name of the student: ");
    stname = Sc.next();

    System.out.print("\nEnter contact number of the student: ");
    stphone = Sc.next();

    System.out.print("\nEnter the Email address of the student: ");
    stemail = Sc.next();
    }

    for(int i1=0; i1<size; i1++){
    System.out.print("\nStudent id is: "+stid[i1]+"\nStudent name is: "+stname[i1]+"\nStudent contact number is: "+stphone[i1]+"\nStudent email is: "+stemail[i1]+"\n");
    }
    }
    }
    හරි නැත්නම් කියපන්.. :)