0% found this document useful (0 votes)
10 views2 pages

30 Essential SQL and Java Programs

Uploaded by

imranamu4u
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

30 Essential SQL and Java Programs

Uploaded by

imranamu4u
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL and Java Programs (15 each)

■ 15 SQL Programs
1. Create a Database:
CREATE DATABASE SchoolDB;

2. Create a Table:
CREATE TABLE Students (RollNo INT PRIMARY KEY, Name VARCHAR(50), Class INT, Marks
INT);

3. Insert Records:
INSERT INTO Students VALUES (1, 'Akshat', 11, 88);

4. Display All Records:


SELECT * FROM Students;

5. Display Students with Marks > 80:


SELECT Name, Marks FROM Students WHERE Marks > 80;

6. Update Student Marks:


UPDATE Students SET Marks = 95 WHERE RollNo = 1;

7. Delete a Record:
DELETE FROM Students WHERE RollNo = 1;

8. Count Total Students:


SELECT COUNT(*) FROM Students;

9. Find Average Marks:


SELECT AVG(Marks) AS AverageMarks FROM Students;

10. Sort Students by Marks:


SELECT * FROM Students ORDER BY Marks DESC;

11. Display Top 3 Students:


SELECT * FROM Students ORDER BY Marks DESC LIMIT 3;

12. Add a New Column:


ALTER TABLE Students ADD COLUMN City VARCHAR(30);

13. Group by Class:


SELECT Class, AVG(Marks) FROM Students GROUP BY Class;

14. Display Students with 'A' in Name:


SELECT * FROM Students WHERE Name LIKE '%A%';

15. Drop the Table:


DROP TABLE Students;

■ 15 Java Programs
1. Print "Hello World":
class Hello { public static void main(String[] args) { [Link]("Hello World"); }}

2. Sum of Two Numbers:


class Sum { public static void main(String[] args) { int a=10,b=20;
[Link]("Sum="+(a+b)); }}
3. Check Even or Odd:
class EvenOdd { public static void main(String[] args) { int n=5; if(n%2==0)
[Link]("Even"); else [Link]("Odd"); }}

4. Find Largest of Three Numbers:


class Largest { public static void main(String[] args) { int a=10,b=25,c=15;
[Link]("Largest:"+[Link](a,[Link](b,c))); }}

5. Check Leap Year:


class LeapYear { public static void main(String[] args) { int year=2024;
if((year%4==0&&year;%100!=0)||year%400==0) [Link]("Leap Year"); else
[Link]("Not Leap Year"); }}

6. Reverse a Number:
class Reverse { public static void main(String[] args) { int n=1234,rev=0;
while(n!=0){rev=rev*10+n%10;n/=10;} [Link]("Reverse="+rev); }}

7. Factorial of a Number:
class Factorial { public static void main(String[] args) { int n=5,fact=1; for(int i=1;i<=n;i++) fact*=i;
[Link]("Factorial="+fact); }}

8. Fibonacci Series:
class Fibonacci { public static void main(String[] args) { int a=0,b=1,c; for(int i=1;i<=10;i++){
[Link](a+" "); c=a+b; a=b; b=c; } }}

9. Palindrome Check:
class Palindrome { public static void main(String[] args) { int n=121,temp=n,rev=0;
while(n>0){rev=rev*10+n%10;n/=10;} [Link](temp==rev?"Palindrome":"Not
Palindrome"); }}

10. Sum of Array Elements:


class ArraySum { public static void main(String[] args) { int[] a={1,2,3,4,5}; int sum=0; for(int x:a)
sum+=x; [Link]("Sum="+sum); }}

11. Find Maximum in Array:


class MaxArray { public static void main(String[] args) { int[] a={10,30,5,25}; int max=a[0]; for(int x:a)
if(x>max) max=x; [Link]("Max="+max); }}

12. Check Prime Number:


class Prime { public static void main(String[] args) { int n=7,count=0; for(int i=1;i<=n;i++) if(n%i==0)
count++; [Link](count==2?"Prime":"Not Prime"); }}

13. Simple Calculator:


class Calculator { public static void main(String[] args) { int a=10,b=5; [Link]("Add:"+
(a+b)); [Link]("Sub:"+(a-b)); [Link]("Mul:"+(a*b));
[Link]("Div:"+(a/b)); }}

14. Sum of Digits:


class SumDigits { public static void main(String[] args) { int n=1234,sum=0;
while(n>0){sum+=n%10;n/=10;} [Link]("Sum="+sum); }}

15. Print Multiplication Table:


class Table { public static void main(String[] args) { int n=5; for(int i=1;i<=10;i++)
[Link](n+" x "+i+" = "+(n*i)); }}

You might also like