Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Bi-Weekly
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arsam Ali
Bi-Weekly
Commits
57e55739
Commit
57e55739
authored
Feb 24, 2023
by
Arsam Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new practice code
parent
590df624
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
522 additions
and
0 deletions
+522
-0
Default.java
src/AccessModifiers/Default.java
+19
-0
Private.java
src/AccessModifiers/Private.java
+25
-0
Protected.java
src/AccessModifiers/Protected.java
+15
-0
Public.java
src/AccessModifiers/Public.java
+21
-0
PracticeConditionalOperators.java
src/ConditionalOperators/PracticeConditionalOperators.java
+31
-0
Nonparametrizedconstructors.java
src/Constructors/Nonparametrizedconstructors.java
+17
-0
ParametrizedConstructor.java
src/Constructors/ParametrizedConstructor.java
+26
-0
SecondExampleConstructor.java
src/Constructors/SecondExampleConstructor.java
+26
-0
IfStatement.java
src/DecisionMaking/IfStatement.java
+79
-0
LeapYearExample.java
src/DecisionMaking/LeapYearExample.java
+13
-0
FillingExamples.java
src/Filling/FillingExamples.java
+56
-0
Abstractions.java
src/Oopconcepts/Abstraction/Abstractions.java
+23
-0
Car.java
src/Oopconcepts/Abstraction/Car.java
+24
-0
Encapsulations.java
src/Oopconcepts/Encupsulation/Encapsulations.java
+19
-0
Vehicle.java
src/Oopconcepts/Inheritance/Vehicle.java
+20
-0
Animal.java
src/Oopconcepts/Polymorphism/Animal.java
+30
-0
StringSplit.java
src/StringMethods/StringSplit.java
+15
-0
StringSubSequence.java
src/StringMethods/StringSubSequence.java
+8
-0
StringcompareTo.java
src/StringMethods/StringcompareTo.java
+13
-0
StringcompareToIgnoreCase.java
src/StringMethods/StringcompareToIgnoreCase.java
+16
-0
Stringlength.java
src/StringMethods/Stringlength.java
+14
-0
StringtoCharArray.java
src/StringMethods/StringtoCharArray.java
+12
-0
No files found.
src/AccessModifiers/Default.java
0 → 100644
View file @
57e55739
package
AccessModifiers
;
class
Student
{
int
rollNo
=
5
;
void
showRollNo
(){
System
.
out
.
println
(
"RollNo = "
+
rollNo
);
}
public
static
void
main
(
String
args
[]){
Student
obj
=
new
Student
();
System
.
out
.
println
(
obj
.
rollNo
);
obj
.
showRollNo
();
}
}
src/AccessModifiers/Private.java
0 → 100644
View file @
57e55739
package
AccessModifiers
;
class
Private
{
private
String
name
;
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
static
void
main
(
String
[]
main
){
Private
d
=
new
Private
();
// access private variable and field from another class
// d.name = "Programiz"; // shows error we have to use getter setter for it
// access the private variable using the getter and setter
d
.
setName
(
"Programiz"
);
System
.
out
.
println
(
d
.
getName
());
}
}
src/AccessModifiers/Protected.java
0 → 100644
View file @
57e55739
package
AccessModifiers
;
class
Protected
{
protected
void
display
()
{
System
.
out
.
println
(
"I am an animal"
);
}
}
class
Dog
extends
Protected
{
public
static
void
main
(
String
[]
args
)
{
Dog
dog
=
new
Dog
();
dog
.
display
();
}
}
src/AccessModifiers/Public.java
0 → 100644
View file @
57e55739
package
AccessModifiers
;
// Animal.java file
// public class
public
class
Public
{
public
int
legCount
;
public
void
display
()
{
System
.
out
.
println
(
"I am an animal."
);
System
.
out
.
println
(
"I have "
+
legCount
+
" legs."
);
}
public
static
void
main
(
String
[]
args
)
{
Public
animal
=
new
Public
();
animal
.
legCount
=
4
;
animal
.
display
();
}
}
src/ConditionalOperators/PracticeConditionalOperators.java
0 → 100644
View file @
57e55739
package
ConditionalOperators
;
public
class
PracticeConditionalOperators
{
public
static
void
main
(
String
[]
args
)
{
String
out
;
int
a
=
6
,
b
=
12
;
out
=
a
==
b
?
"Yes"
:
"No"
;
System
.
out
.
println
(
"Ans: "
+
out
);
//Second Example
int
x
=
5
,
y
=
4
,
z
=
7
;
System
.
out
.
println
(
x
>
y
&&
x
>
z
||
y
<
z
);
System
.
out
.
println
((
x
<
z
||
y
>
z
)
&&
x
<
y
);
//third Example
int
T
,
L
;
T
=
20
;
L
=
(
T
==
1
)
?
61
:
90
;
System
.
out
.
println
(
"Value of y is: "
+
L
);
L
=
(
T
==
20
)
?
61
:
90
;
System
.
out
.
println
(
"Value of y is: "
+
L
);
}
}
src/Constructors/Nonparametrizedconstructors.java
0 → 100644
View file @
57e55739
package
Constructors
;
public
class
Nonparametrizedconstructors
{
private
String
name
;
Nonparametrizedconstructors
()
{
System
.
out
.
println
(
"Constructor Called:"
);
name
=
"Hello This is for Bi-weekly-Practice"
;
}
public
static
void
main
(
String
[]
args
)
{
Nonparametrizedconstructors
obj
=
new
Nonparametrizedconstructors
();
System
.
out
.
println
(
"The name is "
+
obj
.
name
);
}
}
src/Constructors/ParametrizedConstructor.java
0 → 100644
View file @
57e55739
package
Constructors
;
public
class
ParametrizedConstructor
{
String
studentName
;
ParametrizedConstructor
(
String
name
){
studentName
=
name
;
}
ParametrizedConstructor
(
ParametrizedConstructor
myObj
){
this
.
studentName
=
myObj
.
studentName
;
}
void
display
(){
System
.
out
.
println
(
"Student:"
+
studentName
);
}
public
static
void
main
(
String
args
[])
{
ParametrizedConstructor
obj1
=
new
ParametrizedConstructor
(
"Arsam"
);
ParametrizedConstructor
obj2
=
new
ParametrizedConstructor
(
obj1
);
System
.
out
.
println
(
"Printing obj1 - "
);
obj1
.
display
();
System
.
out
.
println
(
"Printing obj2 - "
);
obj2
.
display
();
}
}
src/Constructors/SecondExampleConstructor.java
0 → 100644
View file @
57e55739
package
Constructors
;
public
class
SecondExampleConstructor
{
String
studentName
;
int
studentAge
;
String
member
;
SecondExampleConstructor
(){
member
=
"YES"
;
}
SecondExampleConstructor
(
String
name
,
int
age
){
this
();
studentName
=
name
;
studentAge
=
age
;
}
void
display
(){
System
.
out
.
println
(
studentName
+
" -"
+
studentAge
+
"-"
+
"Member"
+
member
);
}
public
static
void
main
(
String
args
[])
{
SecondExampleConstructor
obj
=
new
SecondExampleConstructor
(
"Arsam"
,
21
);
obj
.
display
();
}
}
src/DecisionMaking/IfStatement.java
0 → 100644
View file @
57e55739
package
DecisionMaking
;
import
java.util.Scanner
;
import
java.util.*
;
public
class
IfStatement
{
public
static
void
main
(
String
args
[]){
int
a
=
20
,
b
=
30
;
if
(
b
>
a
)
System
.
out
.
println
(
"b is greater"
);
}
}
class
Oddeven
{
public
static
void
main
(
String
[]
args
)
{
int
no
;
Scanner
s
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter any number :"
);
no
=
s
.
nextInt
();
if
(
no
%
2
==
0
)
{
System
.
out
.
println
(
"Even number"
);
}
else
{
System
.
out
.
println
(
"Odd number"
);
}
}
}
class
switchCase
{
public
static
void
main
(
String
arg
[])
{
int
ch
;
System
.
out
.
println
(
"Enter any number (1 to 7) :"
);
Scanner
s
=
new
Scanner
(
System
.
in
);
ch
=
s
.
nextInt
();
switch
(
ch
)
{
case
1
:
System
.
out
.
println
(
"Today is Monday"
);
break
;
case
2
:
System
.
out
.
println
(
"Today is Tuesday"
);
break
;
case
3
:
System
.
out
.
println
(
"Today is Wednesday"
);
break
;
case
4
:
System
.
out
.
println
(
"Today is Thursday"
);
break
;
case
5
:
System
.
out
.
println
(
"Today is Friday"
);
break
;
case
6
:
System
.
out
.
println
(
"Today is Saturday"
);
break
;
case
7
:
System
.
out
.
println
(
"Today is Sunday"
);
default
:
System
.
out
.
println
(
"Only enter value 1 to 7"
);
}
}
}
src/DecisionMaking/LeapYearExample.java
0 → 100644
View file @
57e55739
package
DecisionMaking
;
public
class
LeapYearExample
{
public
static
void
main
(
String
args
[])
{
int
year
=
2020
;
if
(((
year
%
4
==
0
)
&&
(
year
%
100
!=
0
))
||
(
year
%
400
==
0
))
{
System
.
out
.
println
(
"LEAP YEAR"
);
}
else
{
System
.
out
.
println
(
"COMMON YEAR"
);
}
}
}
src/Filling/FillingExamples.java
0 → 100644
View file @
57e55739
package
Filling
;
import
java.util.Arrays
;
import
java.util.Scanner
;
public
class
FillingExamples
{
public
static
void
main
(
String
[]
args
)
{
int
size
,
element
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter the size of the array: "
);
size
=
sc
.
nextInt
();
int
[]
array
=
new
int
[
100
];
System
.
out
.
println
(
"Enter the elements in the array: "
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
array
[
i
]
=
sc
.
nextInt
();
}
System
.
out
.
print
(
"Enter the element which you want to fill in the array: "
);
element
=
sc
.
nextInt
();
Arrays
.
fill
(
array
,
element
);
System
.
out
.
println
(
"After filling"
+
element
+
" in complete array:\n"
+
Arrays
.
toString
(
array
));
}
//Second example of Filling
{
int
size
,
element
,
index1
,
index2
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter the size of the array: "
);
size
=
sc
.
nextInt
();
int
[]
array
=
new
int
[
100
];
System
.
out
.
println
(
"Enter the elements in the array: "
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
array
[
i
]
=
sc
.
nextInt
();
}
System
.
out
.
print
(
"Enter the element which you want to fill in the array: "
);
element
=
sc
.
nextInt
();
System
.
out
.
print
(
"From which index you want to fill "
+
element
+
" in the array: "
);
index1
=
sc
.
nextInt
();
System
.
out
.
print
(
"To which index you want to fill "
+
element
+
" in the array: "
);
index2
=
sc
.
nextInt
();
Arrays
.
fill
(
array
,
index1
,
index2
,
element
);
System
.
out
.
println
(
"After filling"
+
element
+
" in the array:\n"
+
Arrays
.
toString
(
array
));
}
}
src/Oopconcepts/Abstraction/Abstractions.java
0 → 100644
View file @
57e55739
package
Oopconcepts
.
Abstraction
;
abstract
class
Animal
{
public
abstract
void
animalSound
();
public
void
sleep
()
{
System
.
out
.
println
(
"Zzz"
);
}
}
class
Cat
extends
Animal
{
public
void
animalSound
()
{
System
.
out
.
println
(
"The cat says: Meowwn"
);
}
}
class
Main
{
public
static
void
main
(
String
[]
args
)
{
Cat
myPig
=
new
Cat
();
myPig
.
animalSound
();
myPig
.
sleep
();
}
}
src/Oopconcepts/Abstraction/Car.java
0 → 100644
View file @
57e55739
package
Oopconcepts
.
Abstraction
;
public
class
Car
{
//data members
private
int
speed
;
private
String
color
;
//getter setters of above data members.
public
int
getSpeed
()
{
return
speed
;
}
public
void
setSpeed
(
int
speed
)
{
this
.
speed
=
speed
;
}
public
String
getColor
()
{
return
color
;
}
public
void
setColor
(
String
color
)
{
this
.
color
=
color
;
}
}
src/Oopconcepts/Encupsulation/Encapsulations.java
0 → 100644
View file @
57e55739
package
Oopconcepts
.
Encupsulation
;
import
Oopconcepts.Abstraction.Car
;
class
CarTest
{
public
static
void
main
(
String
args
[]){
//create Car class object
Car
car1
=
new
Car
();
//set car details.
car1
.
setColor
(
"white"
);
car1
.
setSpeed
(
120
);
//get and print car details.
System
.
out
.
println
(
"Car color: "
+
car1
.
getColor
());
System
.
out
.
println
(
"Car speed: "
+
car1
.
getSpeed
());
}
}
src/Oopconcepts/Inheritance/Vehicle.java
0 → 100644
View file @
57e55739
package
Oopconcepts
.
Inheritance
;
class
Vehicle
{
protected
String
brand
=
"Ford"
;
public
void
honk
()
{
System
.
out
.
println
(
"Tuut, tuut!"
);
}
}
class
Car
extends
Vehicle
{
private
final
String
modelName
=
"Mustang"
;
public
static
void
main
(
String
[]
args
)
{
Car
myCar
=
new
Car
();
myCar
.
honk
();
System
.
out
.
println
(
myCar
.
brand
+
" "
+
myCar
.
modelName
);
}
}
\ No newline at end of file
src/Oopconcepts/Polymorphism/Animal.java
0 → 100644
View file @
57e55739
package
Oopconcepts
.
Polymorphism
;
class
Animal
{
public
void
animalSound
()
{
System
.
out
.
println
(
"The animal makes a sound"
);
}
}
class
cat
extends
Animal
{
public
void
animalSound
()
{
System
.
out
.
println
(
"The cat says: mewee mewee"
);
}
}
class
Dog
extends
Animal
{
public
void
animalSound
()
{
System
.
out
.
println
(
"The dog says: bow wow"
);
}
}
class
Main
{
public
static
void
main
(
String
[]
args
)
{
Animal
myAnimal
=
new
Animal
();
Animal
myCat
=
new
cat
();
Animal
myDog
=
new
Dog
();
myAnimal
.
animalSound
();
myCat
.
animalSound
();
myDog
.
animalSound
();
}
}
\ No newline at end of file
src/StringMethods/StringSplit.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
StringSplit
{
public
static
void
main
(
String
[]
args
)
{
String
text
=
"Arsam Ali Rajput"
;
String
[]
result
=
text
.
split
(
" "
);
System
.
out
.
print
(
"result = "
);
for
(
String
str
:
result
)
{
System
.
out
.
print
(
str
+
", "
);
}
}
}
src/StringMethods/StringSubSequence.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
StringSubSequence
{
public
static
void
main
(
String
[]
args
)
{
String
str
=
"Karachi jami commercial"
;
System
.
out
.
println
(
str
.
subSequence
(
3
,
8
));
}
}
src/StringMethods/StringcompareTo.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
StringcompareTo
{
public
static
void
main
(
String
[]
args
)
{
String
str1
=
"Arsam Ali"
;
String
str2
=
"Hamza Ali"
;
int
result
;
result
=
str1
.
compareTo
(
str2
);
System
.
out
.
println
(
result
);
}
}
src/StringMethods/StringcompareToIgnoreCase.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
StringcompareToIgnoreCase
{
public
static
void
main
(
String
[]
args
)
{
String
str1
=
"Arsam"
;
String
str2
=
"Rahim"
;
String
str3
=
"Umer"
;
int
result
;
result
=
str1
.
compareToIgnoreCase
(
str2
);
System
.
out
.
println
(
result
);
result
=
str1
.
compareToIgnoreCase
(
str3
);
System
.
out
.
println
(
result
);
result
=
str3
.
compareToIgnoreCase
(
str1
);
System
.
out
.
println
(
result
);
}
}
src/StringMethods/Stringlength.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
Stringlength
{
public
static
void
main
(
String
[]
args
)
{
String
str1
=
"nisum pakistan"
;
int
length
=
str1
.
length
();
System
.
out
.
println
(
str1
.
length
());
}
}
src/StringMethods/StringtoCharArray.java
0 → 100644
View file @
57e55739
package
StringMethods
;
public
class
StringtoCharArray
{
public
static
void
main
(
String
[]
args
)
{
String
str
=
"Nisum icon building"
;
char
[]
result
;
result
=
str
.
toCharArray
();
System
.
out
.
println
(
result
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment