Skip to content

Commit d4d1693

Browse files
Add files via upload
1 parent 1713272 commit d4d1693

26 files changed

+633
-0
lines changed

Practice/Armstrong.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.*;
2+
class Armstrong
3+
{
4+
public static void main(String [] args)
5+
{
6+
Scanner s=new Scanner(System.in);
7+
int arm=0,a,b,c,d,no;
8+
System.out.println("Enter the no:");
9+
no=s.nextInt();
10+
d=no;
11+
while(no>0)
12+
{
13+
a=no%10;
14+
no=no/10;
15+
arm=arm+a*a*a;
16+
}
17+
if(arm==d)
18+
{
19+
System.out.println("Armstrong No is="+arm);
20+
}
21+
else
22+
{
23+
System.out.println("No is not armstrong");
24+
}
25+
}
26+
}

Practice/Cons.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Cons
2+
{
3+
Cons(int i){System.out.println(""+i);}
4+
Cons(int a,String str){System.out.println(""+a);System.out.println(""+str);}
5+
public static void main(String[] args)
6+
{
7+
8+
Cons t1=new Cons(10);
9+
Cons t2=new Cons(20,Sundram);
10+
}
11+
}

Practice/Cuboid.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Scanner;
2+
class Cuboid
3+
{
4+
public static void main(String [] args)
5+
{
6+
Scanner s=new Scanner(System.in);
7+
int l,b,h,v,sa;
8+
System.out.println("Enter The Lenght");
9+
l=s.nextInt();
10+
System.out.println("Enter The Breadth");
11+
b=s.nextInt();
12+
System.out.println("Enter The height");
13+
h=s.nextInt();
14+
v=l*b*h;
15+
sa=2*(l*b+b*h+h*l);
16+
System.out.println("Volume:"+v);
17+
System.out.println("Surface Area:"+sa);
18+
}
19+
}

Practice/Reverse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Wap in java to print numbers in reverse order
2+
class Reverse
3+
{
4+
public static void main(String [] args)
5+
{
6+
int i=100;
7+
do
8+
{
9+
System.out.print(i+"\t");
10+
i--;
11+
}
12+
while(i>0);
13+
}
14+
}

Practice/array.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//Wap a pprtogram to print the table of given number using array.
2+
3+
import java.util.*;
4+
class array
5+
{
6+
public static void main(String [] args)
7+
{
8+
int n,i;
9+
int [] tab = new int[10];
10+
Scanner sc = new Scanner(System.in);
11+
System.out.print("Enter a number to print table:");
12+
n=sc.nextInt();
13+
int index=0;
14+
for(i=1;i<=10;i++)
15+
{
16+
tab[index]=n*i;
17+
index++;
18+
}
19+
for(int r:tab)
20+
{
21+
System.out.println(n+"*"+i+"="+r);
22+
}
23+
}
24+
25+
}

Practice/asc.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Wap to store 4 name of your friends into the array and display them in ascending order*/
2+
import java.util.*;
3+
class asc
4+
{
5+
static public void main(String... args)
6+
{
7+
Scanner sc= new Scanner(System.in);
8+
String [] names=new String[5];
9+
int i;
10+
System.out.println("Enter 5 names of your friends");
11+
for(i=0;i<5;i++)
12+
{
13+
names[i]=sc.nextLine();
14+
}
15+
Arrays.sort(names); //Sort array elements in asc order;
16+
17+
for( String a:names)
18+
{
19+
System.out.println("names:"+a);
20+
}
21+
}
22+
}
23+
/*dsc collections.reverse(array_name) it applicable for array list it is the class in collection framework*/

Practice/converse.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Converse
2+
{
3+
static void m1(int[] a)
4+
{
5+
for(int a1:a)
6+
System.out.println(a1);
7+
}
8+
static int[] m2()
9+
{
10+
System.out.println("m1 return");
11+
return new int[]{100,200,300,400};
12+
}
13+
public static void main(String[] args)
14+
{
15+
Converse.m1(new int[]{10,20,30,40});
16+
int[] x=Converse.m2();
17+
for(int x1:x)
18+
System.out.println(x1);
19+
}
20+
}

Practice/dowhile.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Wap in java to print numbers in reverse order
2+
class Reverse
3+
{
4+
public static void main(String [] args)
5+
{
6+
int i=100;
7+
do
8+
{
9+
System.out.println(i+"\t");
10+
i--;
11+
}
12+
while(i>o);
13+
}
14+
}

Practice/fibonacci.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*Fibonacci Series
2+
0 1 1 2 3 5.......................... */
3+
4+
import java.util.*;
5+
class FS
6+
{
7+
public static void main(String [] args)
8+
{
9+
int t1=0,t2=1,t3,i,n;
10+
Scanner s=new Scanner(System.in);
11+
System.out.print("How many terms you want in series ?");
12+
n=s.nextInt();
13+
System.out.print(t1+"\t"+t2+'\t');
14+
for(i=1;i<=n-2;i++)
15+
{
16+
t3=t1+t2;
17+
System.out.print(t3+"\t");
18+
t1=t2;
19+
t2=t3;
20+
}
21+
}
22+
}

Practice/function.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*Function:-The function is a named block of code which perform specific task.
2+
Advantage:
3+
--__--__--__
4+
By using function you can avoid to write same code over and over........
5+
6+
How to define function in JAVA:-In java we give the definition of function inside a class.
7+
Modifiers in Java:-
8+
---------------------------
9+
private---------------
10+
public ! //these are the access modifier
11+
protected -----------
12+
static
13+
final
14+
abstract
15+
native
16+
strictfp
17+
transient
18+
synchronised
19+
volatile.
20+
---------------------------------------------------------------------------------------
21+
SYNTAX OF FUNCTION:
22+
---------------------------------
23+
Modifier return_type function_name(parameters)
24+
{
25+
//code;
26+
}
27+
static int add(int a,int b)
28+
{
29+
return(a+b);
30+
}
31+
*/
32+
//Wap to demonstrate concept of function
33+
class FunDemo
34+
{
35+
void sayhello();
36+
{
37+
System.out.print("Hello");
38+
}
39+
public static void main(String... args)
40+
{
41+
new FunDemo.sayhello();
42+
}
43+
}
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+

0 commit comments

Comments
 (0)