App Icon

BCA Lab Programs

A quick reference for Java syntax and common BCA laboratory practical programs.

public class Sample {
    public static void main(String args[]) {
        System.out.println("Hello World!");
    }
}

All input needs to be entered in the Input tab prior to compilation.

Watch Video
import java.util.Scanner;
  
public class Sample {
    public static void main(String args[]) {
        Scanner reader = new Scanner(System.in);  // Reading from System.in
        
        System.out.println("Enter name: ");
        String name = reader.nextLine(); // Scans the next token
        
        System.out.println("Enter age: ");
        int age = reader.nextInt(); // Scans the next token
        
        System.out.println(name + " is " + age + " years old.");
    }
}
import java.util.Scanner;

class Sample {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value of n:");
        int n = sc.nextInt();
        int sum, mul, rem;
        sum = 0;
        mul = n * n;
        while (mul > 0) {
            rem = mul % 10;
            sum = sum + rem;
            mul = mul / 10;
        }
        if (n == sum) {
            System.out.println(n + " is a neon number");
        } else {
            System.out.println(n + " is NOT a neon number");
        }
    }
}
import java.util.Scanner;

class Student
{
    String USN,NAME,BRANCH;
    float PERCENTAGE;
    long PHONE;
    
    void getdata()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the USN:");
        USN=sc.nextLine();
        System.out.println("Enter the NAME:");
        NAME=sc.nextLine();
        System.out.println("Enter the BRANCH:");
        BRANCH=sc.nextLine();
        System.out.println("Enter the PHONE:");
        PHONE=Long.parseLong(sc.nextLine());
        System.out.println("Enter the PERCENTAGE:");
        PERCENTAGE=Integer.parseInt(sc.nextLine());
    }
    
    void display()
    {
        System.out.println(" ******* STUDENT DETAIL *******");
        System.out.println("USN:"+USN);
        System.out.println("NAME:"+NAME);
        System.out.println("BRANCH:"+BRANCH);
        System.out.println("PHONE:"+PHONE);
        System.out.println("PERCENTAGE:"+PERCENTAGE+"%");
    }
}

class StudentDetails
{
    public static void main(String args[])
    {
        Student obj=new Student();
        obj.getdata();
        obj.display();
    }
}
public class Sample {
    public static void main(String args[]) {
        Employee empOne = new Employee("James Smith");
        empOne.empAge(26);
        empOne.empDesignation("Senior Software Engineer");
        empOne.empSalary(1000);
        empOne.printEmployee();
    }
}

class Employee {
    String name;
    int age;
    String designation;
    double salary;

    public Employee(String name) {
        this.name = name;
    }

    public void empAge(int empAge) {
        age = empAge;
    }

    public void empDesignation(String empDesig) {
        designation = empDesig;
    }
    
    public void empSalary(double empSalary) {
        salary = empSalary;
    }

    public void printEmployee() {
        System.out.println("Name:" + name);
        System.out.println("Age:" + age);
        System.out.println("Designation:" + designation);
        System.out.println("Salary:" + salary);
    }
}
© BCA N.H. Java Compiler Built by Ayush Patil