Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
12 kB
2
Indexable
Never
public class hello1
{
	public static void main(String args[])
	{
		System.out.println(100+100+"BCA Sem4");
		System.out.println("BCA Sem5"+100+100);
	}
}

...................................................................................................................

public class Asciivalue{
    public static void main(String args[]) {
        char ch = 'a';
        int ascii = ch;

        System.out.println("Value" + ch + "is" + ascii);
    }
}

...................................................................................................................

import java.util.*;
class Sum2{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int x,y,z;
        System.out.println("First no.");
        x = in.nextInt();
        System.out.println("Second no.");
        y = in.nextInt();
        z = x + y;
        System.out.println("Sum ="+z);
    }
}

...................................................................................................................

import java.io.*;

class addition1
{
    public static void main(String args[])throws IOException
    {
        int x,y,z;
        InputStreamReader read = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(read);
        System.out.println("Enter the two numbers");
        x = Integer.parseInt(in.readLine());
        y = Integer.parseInt(in.readLine());
        z = x + y;

        System.out.println("the sum of two numbers are " +z);
    }
}

...................................................................................................................

import java.util.Stack;

class stack{
    public static void main(String args[])
    {
        Stack<String> stack1 = new Stack<> ();

        stack1.push("hii");
        stack1.push("hii hii");
        stack1.push("hii hii hii");

        System.out.println("Stack" + stack1);
    
    }
}

...................................................................................................................

import java.util.Vector;

public class vectordemo {
    public static void main(String args[]) {
        Vector<Object> v = new Vector<>();

        int n = 10;
        Integer y = new Integer(20);
        String str = "Sa";

        v.add(n);       
        v.add(y);
        v.add(str);
        v.removeElementAt(1);
        v.add(2, new Integer(30)); 

        System.out.println("Vector contents: " + v);
    }
}

...................................................................................................................

public class Main{
    public static void main(String args[])
    {

        String greet = "Hello! World";
        System.out.println("String:"+ greet);
        int length = greet.length();
        System.out.println("Length:" + length);
    }
}

...................................................................................................................

public class destructoreg{
    public static void main(String args[])
    {
        destructoreg de = new destructoreg();

        de = null;
        System.gc();
        System.out.println("Inside the main() method");
    }
    protected void finalize()throws Throwable 
    {
        System.out.println("Object destroyed by garbage collector");
        super.finalize();
    }
}

...................................................................................................................

public class simpleinterest
{
    public static void main(String args[])
    {
        float p,r,t,si;

        p = 13000;
        r = 12;
        t = 2;

        si = (p * r * t)/100;

        System.out.println("Simple Interest is: " + si);
    }
}

.................................................................................................................

import java.util.Scanner;
public class prime
{
    public static void main(String args[])
    {
        int i, m = 0, a = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number to be checked");
        int n = sc.nextInt();
        m = n/2;
        if (n == 0||n == 1)
        {
            System.out.println(n +"is not prime number");
        } else
        {
            for(i = 2; i < m; i++)
            {
                if(n % i == 0)
                {
                    System.out.println(n+ "is not prime number");
                    a =1;
                    break;
                }
            }
            if (a == 0)
            {
                System.out.println(n+ "is prime number");

                sc.close();
            }
        }
    }
}

................................................................................................................

public class limitprime
{
    public static void main(String[] args)
    {
        int i = 0;
        int num = 0;
        String primeNumbers ="";
        for (i = 1; i <= 50; i++)
        {
            int counter = 0;
            for (num = i; num >= 1; num--)
            {
                if (i % num == 0)
                {
                    counter = counter + 1;
                }
            }
            if (counter == 2)
            {
                primeNumbers = primeNumbers + i + " ";
            }
        }
        System.out.println("Prime numbers from 1 to 50 are:");
        System.out.println(primeNumbers);
    }
}

..................................................................................................................

public class fibo
{
    public static void main(String args[])
    {
        int n1 = 0, n2 = 1, n3,i ,count = 10;
        System.out.println(n1 + " "+ n2);

        for (i = 2; i < count; ++i)
        {
            n3 = n1 + n2;
            System.out.println(" "+n3);
            n1 = n2;
            n2 = n3;
        }
    }
}

.................................................................................................................

import java.util.Arrays;

public class arraysort{
    public static void main(String[] args) {

        int[] array = {5, 3, 8, 1, 2, 7, 4, 6};

        System.out.println("Original array:");
        for (int num : array) {
            System.out.print(num + " ");
        }
        System.out.println();

        Arrays.sort(array);

        System.out.println("Sorted array:");
        for (int num : array) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}

.................................................................................................................

public class MatrixSum 
{
    public static void main(String[] args) 
    {
        int[][] matrix1 = {
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        };

        int[][] matrix2 = {
            {9, 8, 7},
            {6, 5, 4},
            {3, 2, 1}
        };

        int[][] sumMatrix = new int[3][3];

        for (int i = 0; i < matrix1.length; i++) {
            for (int j = 0; j < matrix1[i].length; j++) {
                sumMatrix[i][j] = matrix1[i][j] + matrix2[i][j];
            }
        }

        System.out.println("Matrix 1:");
        displayMatrix(matrix1);

        System.out.println("Matrix 2:");
        displayMatrix(matrix2);

        System.out.println("Sum Matrix:");
        displayMatrix(sumMatrix);
    }

    public static void displayMatrix(int[][] matrix) {
        for (int[] row : matrix) {
            for (int elem : row) {
                System.out.print(elem + " ");
            }
            System.out.println();
        }
    }
}

.................................................................................................................

import java.util.Scanner;

public class HarmonicSeriesSum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Enter the value of n: ");
        int n = scanner.nextInt();
        
        double harmonicSum = 0.0;
        for (int i = 1; i <= n; i++) {
            harmonicSum += 1.0 / i;
        }
        
        System.out.println("The sum of the harmonic series for n = " + n + " is: " + harmonicSum);
    }
}

..................................................................................................................

public class IncrementCounter {
    private static int counter = 0;

    public static void main(String[] args) {
        Thread incrementThread1 = new Thread(new IncrementTask());
        Thread incrementThread2 = new Thread(new IncrementTask());
        
        incrementThread1.start();
        incrementThread2.start();
        
        try {
            incrementThread1.join();
            incrementThread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        System.out.println("Final Counter Value: " + counter);
    }

    static class IncrementTask implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                synchronized (IncrementCounter.class) {
                    counter++;
                }
            }
        }
    }
}

.................................................................................................................

class Employee {
    private String name;
    private double baseSalary;

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

    public double calculateSalary() {
        return baseSalary;
    }

    public String getName() {
        return name;
    }
}

class Manager extends Employee {
    private double bonus;

    public Manager(String name, double baseSalary, double bonus) {
        super(name, baseSalary);
        this.bonus = bonus;
    }

    @Override
    public double calculateSalary() {
        return super.calculateSalary() + bonus;
    }
}

class Programmer extends Employee {
    private int bonusPerProject;
    private int numProjects;

    public Programmer(String name, double baseSalary, int bonusPerProject, int numProjects) {
        super(name, baseSalary);
        this.bonusPerProject = bonusPerProject;
        this.numProjects = numProjects;
    }

    @Override
    public double calculateSalary() {
        return super.calculateSalary() + (bonusPerProject * numProjects);
    }
    public static void main(String[] args) {
        Manager manager = new Manager("John", 50000, 10000);
        Programmer programmer = new Programmer("Alice", 60000, 2000, 5);

        System.out.println("Manager Salary: " + manager.calculateSalary());
        System.out.println("Programmer Salary: " + programmer.calculateSalary());
    }
}

.................................................................................................................

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;

public class ConcentricCirclesApplet extends Applet {

    @Override
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();
        int centerX = width / 2;
        int centerY = height / 2;
        int maxRadius = Math.min(width, height) / 2;
        int numberOfCircles = 10;
        
        // Draw concentric circles
        for (int i = 0; i < numberOfCircles; i++) {
            int radius = maxRadius * (numberOfCircles - i) / numberOfCircles;
            int diameter = 2 * radius;
            g.setColor(new Color(i * 255 / numberOfCircles, 0, 255 - i * 255 / numberOfCircles));
            g.drawOval(centerX - radius, centerY - radius, diameter, diameter);
        }
    }
}

..................................................................................................................

<!DOCTYPE html>
<html>
<body>
    <applet code="ConcentricCirclesApplet.class" width="500" height="500">
    </applet>
</body>
</html>

.................................................................................................................
Leave a Comment