Skip to content

Commit f001ee5

Browse files
GirishN3GirishN3
authored andcommitted
Initial programs
0 parents  commit f001ee5

File tree

11 files changed

+192
-0
lines changed

11 files changed

+192
-0
lines changed

JavaPrograms/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

JavaPrograms/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

JavaPrograms/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JavaPrograms</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

JavaPrograms/src/DupElement.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
public class DupElement {
3+
4+
public static void main(String[] args) {
5+
int [] arr = new int [] {1, 2, 3, 4, 2, 7, 8, 8, 3};
6+
System.out.println("Duplicate elements in given array: ");
7+
//Searches for duplicate element
8+
for(int i = 0; i < arr.length; i++) {
9+
for(int j = i + 1; j < arr.length; j++) {
10+
if(arr[i] == arr[j])
11+
System.out.println(arr[j]);
12+
}
13+
}
14+
15+
}
16+
17+
}

JavaPrograms/src/Factorial.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Scanner;
2+
3+
class Factorial
4+
{
5+
public static void main(String args[])
6+
{
7+
int n, c, fact = 1;
8+
9+
System.out.println("Enter an integer to calculate it's factorial");
10+
Scanner in = new Scanner(System.in);
11+
12+
n = in.nextInt();
13+
14+
if (n < 0)
15+
System.out.println("Number should be non-negative.");
16+
else
17+
{
18+
for (c = 1; c <= n; c++)
19+
fact = fact*c;
20+
21+
System.out.println("Factorial of "+n+" is = "+fact);
22+
}
23+
}
24+
}

JavaPrograms/src/MaxNoArr.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
public class MaxNoArr {
3+
4+
public static void main(String[] args) {
5+
int [] arr = new int [] {25, 11, 7, 75, 56};
6+
//Initialize max with first element of array.
7+
int max = arr[0];
8+
//Loop through the array
9+
for (int i = 0; i < arr.length; i++) {
10+
//Compare elements of array with max
11+
if(arr[i] > max)
12+
max = arr[i];
13+
}
14+
System.out.println("Largest element present in given array: " + max);
15+
16+
}
17+
18+
}

JavaPrograms/src/Palindrome.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Palindrome {
2+
3+
public static void main(String[] args) {
4+
5+
int num = 157, reversedInteger = 0, remainder, originalInteger;
6+
7+
originalInteger = num;
8+
9+
// reversed integer is stored in variable
10+
while( num != 0 )
11+
{
12+
remainder = num % 10;
13+
reversedInteger = reversedInteger * 10 + remainder;
14+
num /= 10;
15+
}
16+
17+
// palindrome if orignalInteger and reversedInteger are equal
18+
if (originalInteger == reversedInteger)
19+
System.out.println(originalInteger + " is a palindrome.");
20+
else
21+
System.out.println(originalInteger + " is not a palindrome.");
22+
}
23+
}

JavaPrograms/src/PrimeNo.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Scanner;
2+
3+
class PrimeNo
4+
{
5+
public static void main(String args[])
6+
{
7+
int n;
8+
9+
System.out.println("Enter an integer to check if its prime");
10+
Scanner in = new Scanner(System.in);
11+
12+
n = in.nextInt();
13+
14+
for(int a=1;a<n/2;a++)
15+
{
16+
if(n%a==0)
17+
{
18+
break;
19+
}
20+
}
21+
}
22+
}

JavaPrograms/src/reverseArray.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
public class reverseArray {
3+
4+
public static void main(String[] args) {
5+
//Initialize array
6+
int [] arr = new int [] {1, 2, 3, 4, 5};
7+
System.out.println("Original array: ");
8+
for (int i = 0; i < arr.length; i++) {
9+
System.out.print(arr[i] + " ");
10+
}
11+
System.out.println();
12+
System.out.println("Array in reverse order: ");
13+
//Loop through the array in reverse order
14+
for (int i = arr.length-1; i >= 0; i--) {
15+
System.out.print(arr[i] + " ");
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)