Skip to content

Commit 1f3748a

Browse files
committed
New Problems
New Problems
1 parent 4e02365 commit 1f3748a

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# your code goes here#Assign x to a Integer
2+
x = 5
3+
print "The value of x is:", x
4+
print "The type of x is:", type(x)
5+
print "The memory location of x is:", id(x)
6+
7+
#Assign x to a Float
8+
x = 6.5
9+
print "The value of x is:", x
10+
print "The type of x is:", type(x)
11+
print "The memory location of x is:", id(x)
12+
13+
#Assign x to a String
14+
x = "CodingDucks.org"
15+
print "The value of x is:", x
16+
print "The type of x is:", type(x)
17+
print "The memory location of x is:", id(x)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
x = 5
2+
print "Memory location of x:",id(x)
3+
4+
x = 6
5+
print "Memory location of x:",id(x)
6+
7+
y = 5
8+
print "Memory location of y:",id(y)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.regex.*;
2+
3+
class RegexDemo{
4+
public static void main (String[] args) throws java.lang.Exception{
5+
//matches numbers only
6+
String regexStr = "^[0-9]*$";
7+
System.out.println(Pattern.matches(regexStr,"97845613000"));
8+
System.out.println(Pattern.matches(regexStr,"19432"));
9+
System.out.println(Pattern.matches(regexStr,"519Ah"));
10+
11+
//matches 10-digit numbers only
12+
regexStr = "^[0-9]{10}$";
13+
System.out.println(Pattern.matches(regexStr,"6576767"));
14+
System.out.println(Pattern.matches(regexStr,"9784561300"));
15+
System.out.println(Pattern.matches(regexStr,"F784561300"));
16+
17+
//matches numbers and dashes, any order really.
18+
regexStr = "^[0-9\\-]*$";
19+
System.out.println(Pattern.matches(regexStr,"97-8456-13-0-0"));
20+
System.out.println(Pattern.matches(regexStr,"9-7-8-4-5-6-1-3-0-0"));
21+
22+
//matches 9999999999, 1-999-999-9999 and 999-999-9999
23+
regexStr = "^(1\\-)?[0-9]{3}\\-?[0-9]{3}\\-?[0-9]{4}$";
24+
System.out.println(Pattern.matches(regexStr,"9784561300"));
25+
System.out.println(Pattern.matches(regexStr,"9-784561300"));
26+
System.out.println(Pattern.matches(regexStr,"978-456-1300"));
27+
System.out.println(Pattern.matches(regexStr,"97-8456-13-0-0"));
28+
}
29+
}

0 commit comments

Comments
 (0)