Skip to content

Commit 659678d

Browse files
committed
updated code
1 parent 348931a commit 659678d

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

module2/CommandLineAgu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public static void main(String args[])
1212
System.out.print("\n"+args[i]);
1313
}
1414
}
15-
}
15+
}

module2/CompareMethod1.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ public class CompareMethod1
1010
public static void main(String args[])
1111
{
1212
System.out.print("\nProgram to demonstate the Overloading of methods");
13-
MethodOverloaded mo = new MethodOverloaded();
13+
//MethodOverloaded mo = new MethodOverloaded();
1414
Scanner reader = new Scanner(System.in);
1515
System.out.print("\n\nEnter two integers: ");
1616
System.out.print("\nFirst: ");
1717
int num1 = reader.nextInt();
1818
System.out.print("\nSecond: ");
1919
int num2 = reader.nextInt();
20-
mo.compare(num1, num2);
20+
compare(num1, num2);
2121

2222
System.out.print("\n\nEnter two characters: ");
2323
System.out.print("\nFirst: ");
2424
char c1 = reader.next().charAt(0) ;
2525
System.out.print("\nSecond: ");
2626
char c2 = reader.next().charAt(0) ;
27-
mo.compare(c1, c2);
27+
compare(c1, c2);
2828

2929
System.out.print("\n\nEnter two Strings: ");
3030
System.out.print("\nFirst: ");
3131
String s1 = reader.next();
3232
System.out.print("\nSecond: ");
3333
String s2 = reader.next();
34-
mo.compare(s1, s2);
34+
compare(s1, s2);
3535
}
36-
public void compare(int x, int y)
36+
void compare(int x, int y)
3737
{
3838
if (x > y)
3939
{
@@ -45,7 +45,7 @@ public void compare(int x, int y)
4545
}
4646
}
4747

48-
public void compare(char ch1, char ch2)
48+
void compare(char ch1, char ch2)
4949
{
5050
int x = (int) ch1;
5151
int y = (int) ch2;
@@ -59,7 +59,7 @@ public void compare(char ch1, char ch2)
5959
}
6060
}
6161

62-
public void compare(String str1, String str2)
62+
void compare(String str1, String str2)
6363
{
6464
if(str1.compareTo(str2) > 0)
6565
{

module2/StaticVsNonStaticMethod.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public static void main(String args[])
3838
ob2.increaseCount();
3939
ob2.increaseCount();
4040
ob2.increaseCount();
41-
ob2.printCount();
41+
ob2.printCount();
42+
StaticNonStaticMethod ob3 = new StaticNonStaticMethod();
43+
StaticNonStaticMethod.objectCount();
44+
StaticNonStaticMethod ob4 = new StaticNonStaticMethod();
45+
StaticNonStaticMethod.objectCount();
46+
ob4.printCount();
47+
4248
}
43-
}
49+
}

module2/VariableLenArgu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public static void main(String args[])
1616

1717
class VariableArgu
1818
{
19-
void print_arguments(String... str)
19+
void print_arguments(String... str)// Method Accepting Variable Length Aruguments
2020
{
2121
for(String s:str)
2222
{
2323
System.out.print(s);
2424
}
2525
}
26-
}
26+
}

module3/ReplaceVowels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static void main(String args[])
88
System.out.print("Enter a string: ");
99
String str= sc.nextLine(); //reads string
1010
System.out.print("The string after replacing vowels: ");
11-
str = str.replaceAll("[aeiouAEIOU]", "@"); // Replace Vowels by $
11+
str = str.replaceAll("[a-zA-Z]", "@"); // Replace Vowels by $
1212
System.out.println(str);
1313
}
1414
}

module3/Uniquesubstringcount.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Program to count the number of occurrences of a search string in a given text string.
2+
import java.io.*;
3+
import java.util.Scanner;
4+
class SubStringCount
5+
{
6+
static int countOccurrences(String str, String word)
7+
{
8+
String a[] = str.split(" ");
9+
int count = 0;
10+
for (int i = 0; i < a.length; i++)
11+
{
12+
if (word.equals(a[i]))
13+
count++;
14+
}
15+
return count;
16+
}
17+
public static void main(String args[])
18+
{
19+
Scanner sc = new Scanner(System.in);
20+
System.out.print("\nEnter a string:");
21+
String str = sc.nextLine();
22+
System.out.println("\nEnter a word to check for occurences:");
23+
String word = sc.nextLine();
24+
System.out.print(countOccurrences(str, word));
25+
}
26+
}

0 commit comments

Comments
 (0)