Skip to content

Commit 651114b

Browse files
Merge pull request #78 from Zobiya-Jumani21/master
basic-java-programs
2 parents 1227706 + 3c14375 commit 651114b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2306
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Array{
2+
3+
public static void main(String args []){
4+
5+
// System.out.print(args[0]);
6+
7+
/*for(int i=0; i<args.length; i++){
8+
System.out.println(args[i]); */
9+
10+
int sum=0;
11+
for(int i=0; i<args.length; i++)
12+
sum=sum+Integer.parseInt(args[i]);
13+
System.out.print("sum ="+sum);
14+
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Ascii{
2+
3+
public static void main(String args [ ]){
4+
5+
int num=0;
6+
char ch;
7+
8+
do{
9+
ch =(char)num;
10+
11+
System.out.print(ch + " ,");
12+
num++;
13+
}
14+
while(num!=255);
15+
16+
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Average{
2+
3+
public static void main(String args []){
4+
5+
float num1=4F, num2=3.6F, num3=22.2F, num4=5.5F, num5=7.6F;
6+
float sum,average;
7+
8+
sum=num1+num2+num3+num4+num5;
9+
10+
average=sum/5;
11+
12+
System.out.println("Sum is : " +sum);
13+
System.out.println("Average is : " + average);
14+
15+
}
16+
}
17+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class Bitwise{
2+
public static void main(String []args){
3+
int x=4;
4+
int y=3, z=-4,result;
5+
6+
result=y|x;
7+
System.out.print(result);
8+
9+
10+
result=y&x;
11+
System.out.println( );
12+
System.out.print(result);
13+
14+
result=y^x;
15+
System.out.println( );
16+
System.out.print(result);
17+
18+
System.out.println( );
19+
System.out.print(~x);
20+
21+
22+
}}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class By{
2+
String name;
3+
int age;
4+
String rollNum;
5+
6+
By( ) { name="ABC";
7+
age= 00;
8+
rollNum="GGG";}
9+
10+
By( String n, int a , String r){
11+
name=n;
12+
age=a;
13+
rollNum=r;}
14+
15+
By (By B){
16+
this.name=B.name;
17+
this.age=B.age;
18+
this.rollNum=B.rollNum;}
19+
20+
void duplicate(By B){
21+
//this.name=B.name;
22+
this.rollNum=B.rollNum;
23+
this.name=B.name="Na";
24+
}
25+
26+
27+
public static void main(String args []){
28+
By b1, b2, b3,s4;
29+
b1= new By();
30+
b2= new By("Zobiya" , 111, "21sw140");
31+
b3= new By(b2.name);
32+
System.out.print(s1.name);
33+
s4 = new By( );
34+
s4.duplicate(s2);
35+
36+
}
37+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Scanner;
2+
3+
class Calculator{
4+
5+
public static void main(String args []){
6+
7+
8+
Scanner input = new Scanner(System.in);
9+
10+
System.out.print("Enter a first number : ");
11+
12+
int num1= input.nextInt();
13+
14+
System.out.println("Enter a second number : ");
15+
16+
int num2 =input.nextInt();
17+
18+
System.out.println("Enter Any Operation [+,-,*,/] : ");
19+
20+
char ch =input.next( ).charAt(0);
21+
float sum,product,sub,division;
22+
23+
switch(ch)
24+
{
25+
case '+' :
26+
sum=num1+num2;
27+
System.out.print("Sum of two number is : " + sum);
28+
break;
29+
30+
case '-' :
31+
sub=num1-num2;
32+
System.out.print("Sub of number one from number two is : " + sub);
33+
break;
34+
35+
case '*' :
36+
product=num1*num2;
37+
System.out.print("product of two number is : " + product);
38+
break;
39+
40+
case '/' :
41+
division=num1/num2;
42+
System.out.print("Division of number 1 with number 2 is : " + division);
43+
break;
44+
45+
46+
default :
47+
System.out.print("DEfault ");
48+
}
49+
}
50+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Camera{
2+
3+
public static void main(String args []){
4+
5+
for(int i=0; i<args.length; i++){
6+
7+
8+
System.out.print(args [i]);
9+
}
10+
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Car{
2+
3+
static int num_of_weeks;
4+
5+
Car( ){ ++num_of_weeks;}
6+
7+
public static void main(String args []){
8+
9+
System.out.println(Car.num_of_weeks); // without constructer output is 0
10+
11+
Car.num_of_weeks=4;
12+
System.out.println(Car.num_of_weeks); // in main function we give value 4
13+
14+
Car car1=new Car( );
15+
16+
System.out.println(car1.num_of_weeks); //with the constructer 5
17+
}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import java.util.Scanner;
3+
4+
class Cast{
5+
public static void main(String args []){
6+
7+
Scanner scan = new Scanner(System.in);
8+
9+
System.out.print("Enter the value");
10+
11+
double d = scan.nextDouble();
12+
13+
int n=(int)d;
14+
System.out.println("Integer value is : " + " " + n);
15+
double f=d-n;
16+
System.out.println("fraction value is : " + " " + f);
17+
18+
}
19+
}
20+
21+
22+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import java.util.ArrayList;
2+
class University {
3+
4+
String uname;
5+
ArrayList<Students> studentsList = new ArrayList<Students>();
6+
ArrayList<Departments> deptList = new ArrayList<Departments>();
7+
8+
// one argunment Constructer when we pass the name of student in return the object
9+
University(String uni, String[] snames, String[] dnames) {
10+
uname=uni;
11+
// to find out number of names which are pass in this object we write for loop
12+
for (int i = 0; i < snames.length; i++) {
13+
studentsList.add(new Students(snames[i]));
14+
}
15+
for (int j = 0; j < dnames.length; j++) {
16+
deptList.add(new Departments(dnames[j]));
17+
}
18+
} // end of constructer
19+
20+
// students class inside university class
21+
class Students {
22+
String snames;
23+
Departments dept;
24+
25+
Students(String snames) {
26+
this.snames = snames;
27+
}
28+
29+
void display() {
30+
System.out.print(" name of the student is : " + snames);
31+
32+
}
33+
}
34+
35+
class Departments {
36+
String dnames;
37+
ArrayList<Students>deptstudents = new ArrayList<Students>();
38+
39+
Departments(String dnames) {
40+
this.dnames = dnames;
41+
}
42+
43+
// display all the students name which are study in that department
44+
public void displayStudents() {
45+
for (int i = 0; i < deptstudents.size(); i++) {
46+
System.out.println(deptstudents.get(i).snames);
47+
48+
}
49+
}
50+
} // end of departments class
51+
52+
Departments getDepartments(String name) {
53+
for (int i = 0; i < deptList.size(); i++) {
54+
if (deptList.get(i).dnames.equals(name))
55+
return deptList.get(i);
56+
}
57+
return null;
58+
}
59+
60+
Students getstudents(String name) {
61+
for (int j = 0; j < studentsList.size(); j++) {
62+
if (studentsList.get(j).snames.equals(name))
63+
return studentsList.get(j);
64+
}
65+
return null;
66+
}
67+
68+
public void enrollIn(Departments d, Students s) {
69+
s.dept = d;
70+
d.deptstudents.add(s);
71+
}
72+
73+
public void displayStudentsInDept(Departments d) {
74+
d.displayStudents();
75+
}
76+
77+
}
78+
// university class end here
79+
public class Charyo{
80+
public static void main(String[] args) {
81+
String [] snames={ "Ali","Mohsin","Ahsan","Muhsin","Zakir"};
82+
String [] dept= {"SW","CS"};
83+
University muet=new University("Mehran UET ",snames,dept);
84+
muet.enrollIn(muet.getDepartments("SW"),muet.getstudents("Ali") );
85+
muet.displayStudentsInDept(muet.getDepartments("SW"));
86+
}
87+
}

0 commit comments

Comments
 (0)