Skip to content

Commit 34a8adb

Browse files
SpreehaMadhavBahl
authored andcommitted
day 30 (#213)
1 parent 79c2a9b commit 34a8adb

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

day30/Java/naive.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package javaapplication3;
7+
8+
/**
9+
* @date 30/01/19
10+
* @author SPREEHA DUTTA
11+
*/
12+
import java.util.*;
13+
public class naive {
14+
public static void main(String []args)
15+
{
16+
Scanner sc=new Scanner(System.in);
17+
String s,p;int i,j;String str;int c=0;
18+
s=sc.next();
19+
System.out.println("Enter pattern ");
20+
p=sc.next();
21+
for(i=0;i<s.length()-p.length();i++)
22+
{
23+
str=s.substring(i,i+p.length());
24+
if(str.equals(p))
25+
{
26+
System.out.println(i); c=1;
27+
break;
28+
}
29+
}
30+
if(c==0)
31+
System.out.println("Pattern not found");
32+
}
33+
}

day30/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,39 @@ output: 6 (start index of the found pattern)
2828
to be added
2929
```
3030

31+
## Java Implementation
32+
33+
### [Solution](./Java/naive.java)
34+
35+
```java
36+
/**
37+
* @date 30/01/19
38+
* @author SPREEHA DUTTA
39+
*/
40+
import java.util.*;
41+
public class naive {
42+
public static void main(String []args)
43+
{
44+
Scanner sc=new Scanner(System.in);
45+
String s,p;int i,j;String str;int c=0;
46+
s=sc.next();
47+
System.out.println("Enter pattern ");
48+
p=sc.next();
49+
for(i=0;i<s.length()-p.length();i++)
50+
{
51+
str=s.substring(i,i+p.length());
52+
if(str.equals(p))
53+
{
54+
System.out.println(i); c=1;
55+
break;
56+
}
57+
}
58+
if(c==0)
59+
System.out.println("Pattern not found");
60+
}
61+
}
62+
```
63+
3164
### [C++ Implementation](./C++/naiveSearch.cpp)
3265

3366
```cpp
@@ -110,3 +143,4 @@ int main(){
110143
return 0;
111144
}
112145
```
146+

0 commit comments

Comments
 (0)