Skip to content

Commit 7ae70cc

Browse files
Add Java programming practice programs
0 parents  commit 7ae70cc

23 files changed

Lines changed: 431 additions & 0 deletions

.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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-21">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

.gitignore

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

.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>java_Programming_Practice</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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
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.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
4+
org.eclipse.jdt.core.compiler.compliance=21
5+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
6+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
7+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
8+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
9+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
10+
org.eclipse.jdt.core.compiler.release=enabled
11+
org.eclipse.jdt.core.compiler.source=21

src/module-info.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
*
3+
*/
4+
/**
5+
*
6+
*/
7+
module java_Progamming_Practice {
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package number_Programming.core.day_01;
2+
import java.util.*;
3+
// 4.write a program to count the numbers between m to n
4+
public class Count
5+
{
6+
public static int count(int m , int n)
7+
{
8+
int count = 0;
9+
for(int i = m ;i<=n;i++)
10+
{
11+
count++;
12+
}
13+
return count;
14+
}
15+
public static void main(String[] args) {
16+
Scanner sc = new Scanner(System.in);
17+
System.out.println("enter m value :");
18+
int m = sc.nextInt();
19+
System.out.println("enter n value : ");
20+
int n = sc.nextInt();
21+
System.out.println("count of numbers from range " + m + " to " + n + " is " + count(m, n));
22+
sc.close();
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package number_Programming.core.day_01;
2+
import java.util.*;
3+
//16.wapt count the number of digits in a given number
4+
public class CountDigits
5+
{
6+
public static int count(int num)
7+
{
8+
int count = 0;
9+
while(num>0)
10+
{
11+
num= num/10;
12+
count++;
13+
}
14+
return count;
15+
}
16+
public static void main(String[] args) {
17+
Scanner sc = new Scanner(System.in);
18+
System.out.println("Enter a number : ");
19+
int num = sc.nextInt();
20+
System.out.println("The count of digits in the number :" + count(num));
21+
sc.close();
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package number_Programming.core.day_01;
2+
import java.util.*;
3+
//9.write a program to produce the cube of a given number
4+
public class Cube {
5+
6+
public static void main(String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
System.out.println("Enter a number ");
10+
int num = sc.nextInt();
11+
int cube = num * num * num ;
12+
System.out.println("The cube of the given number is " + cube);
13+
// TODO Auto-generated method stub
14+
15+
}
16+
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package number_Programming.core.day_01;
2+
import java.util.*;
3+
//1.write a program to check whether the number is even or odd
4+
public class EvenOrOdd
5+
{
6+
7+
public static void evenOdd(int num)
8+
{
9+
if(num % 2 == 0)
10+
{
11+
System.out.println("Number is even ");
12+
13+
}
14+
else
15+
System.out.println("Number is odd");
16+
}
17+
18+
public static void main(String[] args)
19+
{
20+
Scanner sc = new Scanner(System.in);
21+
System.out.println("Enter a number : ");
22+
int num = sc.nextInt();
23+
evenOdd(num);
24+
sc.close();
25+
}
26+
27+
28+
}

0 commit comments

Comments
 (0)