Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assignment-10
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
Muhammad Abdul Qadeer Farooqui
Assignment-10
Commits
bbdd7045
Commit
bbdd7045
authored
May 31, 2022
by
Muhammad Abdul Qadeer Farooqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
problem solving assignment
parent
064c23ef
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
33 deletions
+54
-33
vcs.xml
.idea/vcs.xml
+6
-0
DateFormat.class
out/production/Assignment_10/DateFormat.class
+0
-0
IsString.class
out/production/Assignment_10/IsString.class
+0
-0
DateFormat.java
src/DateFormat.java
+23
-19
IsString.java
src/IsString.java
+25
-14
No files found.
.idea/vcs.xml
0 → 100644
View file @
bbdd7045
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
out/production/Assignment_10/DateFormat.class
View file @
bbdd7045
No preview for this file type
out/production/Assignment_10/IsString.class
View file @
bbdd7045
No preview for this file type
src/DateFormat.java
View file @
bbdd7045
...
@@ -6,25 +6,29 @@ import java.util.TimeZone;
...
@@ -6,25 +6,29 @@ import java.util.TimeZone;
public
class
DateFormat
{
public
class
DateFormat
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// LocalDateTime d = LocalDateTime.now();
LocalDateTime
d
=
LocalDateTime
.
now
();
//
//
//// Date Format1: Tue Aug 01 10:50:30 2017
// Date Format1: Tue Aug 01 10:50:30 2017
//// Date Format2: 2017 Aug 01 10:50:30
// Date Format2: 2017 Aug 01 10:50:30
//
// DateTimeFormatter df1 = DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss yyyy");
DateTimeFormatter
df1
=
DateTimeFormatter
.
ofPattern
(
"E MMM dd HH:mm:ss yyyy"
);
// String fd1 = d.format(df1);
String
fd1
=
d
.
format
(
df1
);
// System.out.println(fd1);
System
.
out
.
println
(
fd1
);
//
// DateTimeFormatter df2 = DateTimeFormatter.ofPattern("yyyy MMM dd HH:mm:ss");
DateTimeFormatter
df2
=
DateTimeFormatter
.
ofPattern
(
"yyyy MMM dd HH:mm:ss"
);
// String fd2 = d.format(df2);
String
fd2
=
d
.
format
(
df2
);
// System.out.println(fd2);
System
.
out
.
println
(
fd2
);
// add days to date
// add month to date
LocalDateTime
date
=
LocalDateTime
.
now
().
plusDays
(-
15
);
LocalDateTime
myMonth
=
LocalDateTime
.
now
().
plusMonths
(
1
);
DateTimeFormatter
dateFormat
=
DateTimeFormatter
.
ofPattern
(
"E MMM dd HH:mm:ss yyyy"
);
DateTimeFormatter
monthFormat
=
DateTimeFormatter
.
ofPattern
(
"E MMM dd HH:mm:ss yyyy"
);
String
dateString
=
date
.
format
(
dateFormat
);
System
.
out
.
println
(
"After adding 1 month: "
+
myMonth
.
format
(
monthFormat
));
System
.
out
.
println
(
dateString
);
// subtract days to date
LocalDateTime
myDay
=
LocalDateTime
.
now
().
plusDays
(-
15
);
DateTimeFormatter
dayFormat
=
DateTimeFormatter
.
ofPattern
(
"E MMM dd HH:mm:ss yyyy"
);
System
.
out
.
println
(
"After subtracting 15 days: "
+
myDay
.
format
(
dayFormat
));
}
}
}
}
src/IsString.java
View file @
bbdd7045
...
@@ -9,22 +9,33 @@ import java.util.regex.Pattern;
...
@@ -9,22 +9,33 @@ import java.util.regex.Pattern;
public
class
IsString
{
public
class
IsString
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
String
re
=
"-?\\d+(\\.\\d+)?"
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter a valid string: "
);
System
.
out
.
println
(
"Enter a valid string: "
);
String
myStr
=
sc
.
next
();
String
myStr
=
sc
.
nextLine
();
// System.out.println(myStr);
// Pattern pattern = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE);
int
status
=
0
;
// Matcher matcher = pattern.matcher(myStr);
int
count
=
0
;
// boolean matchFound = matcher.find();
for
(
int
i
=
0
;
i
<
myStr
.
length
();
i
++)
{
Pattern
pt
=
Pattern
.
compile
(
re
);
char
c
=
myStr
.
charAt
(
i
);
Matcher
mt
=
pt
.
matcher
(
myStr
);
// regex for capital and small alphabets
boolean
result
=
mt
.
matches
();
if
(
Pattern
.
matches
(
"[a-zA-z]"
,
String
.
valueOf
(
c
)))
{
if
(
myStr
.
contains
(
"[0-9]+"
))
{
}
System
.
out
.
println
(
"valid"
);
// regex for white space
else
if
(
Pattern
.
matches
(
"[\\s]"
,
""
+
c
)){
count
++;
}
else
{
status
=
-
1
;
break
;
}
}
if
(
count
==
myStr
.
length
())
{
System
.
out
.
println
(
"invalid"
);
}
else
if
(
status
==
-
1
)
{
System
.
out
.
println
(
"invalid"
);
}
else
{
}
else
{
System
.
out
.
println
(
"
not
valid"
);
System
.
out
.
println
(
"valid"
);
}
}
}
}
}
}
\ No newline at end of file
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