Skip to content

Commit b14d7ff

Browse files
authored
Add files via upload
1 parent c21959d commit b14d7ff

18 files changed

+513
-0
lines changed

AddingElementVect.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.*;
2+
import java.io.*;
3+
class AddingElementVect
4+
{
5+
public static void main(String args[])
6+
{
7+
8+
9+
Vector v=new Vector();
10+
v.addElement(new Integer(10));
11+
v.addElement(new Integer(20));
12+
v.addElement(new Float(1.2));
13+
v.addElement(new Float(1.3));
14+
v.addElement(new Character('A'));
15+
v.addElement(new Character('S'));
16+
v.addElement(new String("Core"));
17+
v.addElement(new String("Java"));
18+
System.out.println(v);
19+
20+
System.out.println("We will search 20");
21+
System.out.println("Present or not?"+v.contains(20));
22+
System.out.println("We will search D");
23+
System.out.println("Present or not?"+v.contains('D'));
24+
25+
v.removeAllElements();
26+
System.out.println(v);
27+
}
28+
}
29+

Bitwise.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//To demonstrate bitwise operators
2+
import java.util.*;
3+
class Bitwise
4+
{
5+
public static void main(String args[])
6+
{
7+
int a,b,c,ans;
8+
Scanner sc=new Scanner(System.in);
9+
System.out.print("Enter value of a: ");
10+
a=sc.nextInt();
11+
System.out.print("Enter value of b: ");
12+
b=sc.nextInt();
13+
System.out.print("Enter value of c: ");
14+
c=sc.nextInt();
15+
ans=a & b;
16+
System.out.println("Bitwise ANDing a & b: "+ans);
17+
ans=a | b;
18+
System.out.println("Bitwise ORing a | b: "+ans);
19+
ans=a ^ b;
20+
System.out.println("Bitwise EX-ORing a ^ b: "+ans);
21+
ans=c<<1;
22+
System.out.println("Bitwise LEFT SHIFT c<<1: "+ans);
23+
ans=c>>1;
24+
System.out.println("Bitwise RIGHT SHIFT c>>1: "+ans);
25+
ans=c>>>1;
26+
System.out.println("Bitwise RIGHT SHIFT WITH FILL ZERO c>>>1: "+ans);
27+
ans=~a;
28+
System.out.println("Bitwise COMPLEMENT ~a: "+ans);
29+
}
30+
}
31+
32+

MultiCatch.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class MultiCatch {
2+
public static void main(String args[]) {
3+
int a[]={5,10};
4+
int b=5;
5+
try {
6+
int x=a[2]/b-a[1];
7+
System.out.println("x= "+x);
8+
}
9+
catch(ArithmeticException e) {
10+
System.out.println(e);
11+
}
12+
catch(ArrayIndexOutOfBoundsException e) {
13+
System.out.println(e);
14+
}
15+
catch(ArrayStoreException e) {
16+
System.out.println(e);
17+
}
18+
int y=a[1]/a[0];
19+
System.out.println("y= "+y);
20+
}
21+
}

Pattern1.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//To print * pattern
2+
class Pattern1
3+
{
4+
public static void main(String [] args)
5+
{
6+
int i,j,n;
7+
n=Integer.parseInt(args[0]);
8+
for(i=1;i<=n;i++)
9+
{
10+
for(j=1;j<=i;j++)
11+
{
12+
System.out.print(" * ");
13+
}
14+
System.out.println( );
15+
}
16+
}
17+
}

Rectangle.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Program to calculate area and perimeter of rectangle
2+
import java.util.*;
3+
class Rectangle
4+
{
5+
public static void main(String args[])
6+
{
7+
int l,b,a,p;
8+
System.out.print("Input length and breadth: ");
9+
Scanner sc=new Scanner(System.in);
10+
l=sc.nextInt();
11+
b=sc.nextInt();
12+
a=l*b;
13+
p=2*(l+b);
14+
System.out.println("Area: "+a);
15+
System.out.println("Perimeter: "+p);
16+
}
17+
}

ReverseNo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//Reversing a number
2+
import java.lang.*; //This package is imported by default. No error occurs if we skip this line
3+
import java.util.*;
4+
class ReverseNo
5+
{
6+
public static void main(String args[])
7+
{
8+
int num,rev=0,rem;
9+
System.out.print("Enter a number: ");
10+
Scanner sc=new Scanner(System.in);
11+
num=sc.nextInt();
12+
while(num>0)
13+
{
14+
rem=num%10;
15+
rev=rev*10+rem;
16+
num=num/10;
17+
}
18+
System.out.println("Reverse: "+rev);
19+
}
20+
}

RunnableDemo.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//Multithreading by implementing runnable interface
2+
class A implements Runnable {
3+
public void run() {
4+
for(int i=1;i<=5;i++) {
5+
System.out.println("i = "+i);
6+
}
7+
System.out.println("Exit from A");
8+
}
9+
}
10+
class B implements Runnable {
11+
public void run() {
12+
for(int j=1;j<=5;j++) {
13+
System.out.println("j = "+j);
14+
}
15+
System.out.println("Exit from B");
16+
}
17+
}
18+
class C implements Runnable {
19+
public void run() {
20+
for(int k=1;k<=5;k++) {
21+
System.out.println("k = "+k);
22+
}
23+
System.out.println("Exit from C");
24+
}
25+
}
26+
class RunnableDemo {
27+
public static void main(String args[]) {
28+
A aobj = new A();
29+
Thread t1=new Thread(aobj);
30+
t1.start();
31+
B bobj = new B();
32+
Thread t2=new Thread(bobj);
33+
t2.start();
34+
C cobj = new C();
35+
Thread t3=new Thread(cobj);
36+
t3.start();
37+
}
38+
}

SearchlastString.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class SearchlastString {
2+
public static void main(String[] args) {
3+
String strOrig = "Hello world ,Hello Java Students, Welcome to Java practical";
4+
int lastIndex = strOrig.lastIndexOf("Java");
5+
6+
if(lastIndex == - 1){
7+
System.out.println("Java not found");
8+
} else {
9+
System.out.println("Last occurrence of Java is at index "+ lastIndex);
10+
}
11+
}
12+
}

StringReverse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class StringReverse
2+
{
3+
public static void main(String args[])
4+
{
5+
StringBuffer sb=new StringBuffer("programming");
6+
System.out.println("Result: "+sb.reverse());
7+
}
8+
}

SwingCalendar.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import java.util.*;
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import javax.swing.*;
5+
import javax.swing.table.*;
6+
7+
public class SwingCalendar extends JFrame {
8+
9+
DefaultTableModel model;
10+
Calendar cal = new GregorianCalendar();
11+
JLabel label;
12+
13+
SwingCalendar() {
14+
15+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16+
this.setTitle("Swing Calandar");
17+
this.setSize(300,200);
18+
this.setLayout(new BorderLayout());
19+
this.setVisible(true);
20+
21+
22+
label = new JLabel();
23+
label.setHorizontalAlignment(SwingConstants.CENTER);
24+
25+
JButton b1 = new JButton("<-");
26+
b1.addActionListener(new ActionListener() {
27+
public void actionPerformed(ActionEvent ae) {
28+
cal.add(Calendar.MONTH, -1);
29+
updateMonth();
30+
}
31+
});
32+
33+
JButton b2 = new JButton("->");
34+
b2.addActionListener(new ActionListener() {
35+
public void actionPerformed(ActionEvent ae) {
36+
cal.add(Calendar.MONTH, +1);
37+
updateMonth();
38+
}
39+
});
40+
41+
JPanel panel = new JPanel();
42+
panel.setLayout(new BorderLayout());
43+
panel.add(b1,BorderLayout.WEST);
44+
panel.add(label,BorderLayout.CENTER);
45+
panel.add(b2,BorderLayout.EAST);
46+
47+
48+
String [] columns = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
49+
model = new DefaultTableModel(null,columns);
50+
JTable table = new JTable(model);
51+
JScrollPane pane = new JScrollPane(table);
52+
53+
this.add(panel,BorderLayout.NORTH);
54+
this.add(pane,BorderLayout.CENTER);
55+
56+
this.updateMonth();
57+
58+
}
59+
60+
void updateMonth() {
61+
cal.set(Calendar.DAY_OF_MONTH, 1);
62+
63+
String month = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US);
64+
int year = cal.get(Calendar.YEAR);
65+
label.setText(month + " " + year);
66+
67+
int startDay = cal.get(Calendar.DAY_OF_WEEK);
68+
int numberOfDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
69+
int weeks = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
70+
71+
model.setRowCount(0);
72+
model.setRowCount(weeks);
73+
74+
int i = startDay-1;
75+
for(int day=1;day<=numberOfDays;day++){
76+
model.setValueAt(day, i/7 , i%7 );
77+
i = i + 1;
78+
}
79+
80+
}
81+
82+
public static void main(String[] arguments) {
83+
JFrame.setDefaultLookAndFeelDecorated(true);
84+
SwingCalendar sc = new SwingCalendar();
85+
}
86+
87+
}
88+

0 commit comments

Comments
 (0)