Skip to content

Commit 6963034

Browse files
authored
Merge pull request larissalages#252 from sakshi-kst/master
Hackerrank- Java and 30DaysOfCode solutions added
2 parents 3760d0d + c18f4e2 commit 6963034

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
6+
public static void main(String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
int n = sc.nextInt();
10+
for(int i=0; i<n; i++)
11+
{
12+
int c = 0;
13+
int p = sc.nextInt();
14+
if(p==1)
15+
System.out.println("Not prime");
16+
for(int j=2; j*j<=p;j++)
17+
{
18+
if(p%j==0)
19+
{
20+
System.out.println("Not prime");
21+
c++;
22+
break;
23+
}
24+
}
25+
if(c==0 && p!=1)
26+
System.out.println("Prime");
27+
}
28+
}
29+
}

Hackerrank/java/Java_2D_Array.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
12+
13+
private static final Scanner scanner = new Scanner(System.in);
14+
15+
public static void main(String[] args) {
16+
int[][] arr = new int[6][6];
17+
int max = -70;
18+
19+
for (int i = 0; i < 6; i++) {
20+
String[] arrRowItems = scanner.nextLine().split(" ");
21+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
22+
23+
for (int j = 0; j < 6; j++) {
24+
int arrItem = Integer.parseInt(arrRowItems[j]);
25+
arr[i][j] = arrItem;
26+
}
27+
}
28+
29+
for(int i=0;i<4;i++)
30+
{
31+
for(int j=0;j<4;j++)
32+
{
33+
int sum = arr[i][j] + arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
34+
if(sum >= max)
35+
max = sum;
36+
}
37+
}
38+
39+
System.out.println(max);
40+
41+
scanner.close();
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
6+
public static void main(String[] args) {
7+
Scanner scan = new Scanner(System.in);
8+
String s = scan.nextLine().trim();
9+
10+
String[] str = s.split("[ !,?._'@]+");
11+
int l = str.length;
12+
if(s.compareTo("")==0)
13+
System.out.println(0);
14+
else
15+
{
16+
System.out.println(l);
17+
for(int i=0;i<l;i++)
18+
System.out.println(str[i]);
19+
}
20+
scan.close();
21+
}
22+
}

0 commit comments

Comments
 (0)