Practical PRGM - Unit I
Practical PRGM - Unit I
Output:
6 6 6
12 12 12
18 18 18
class Sample
{
public static void main(String args[])
{
int i;
String m[ ]={"Anith","Ben","Rajiv","Vijay","Zafa"};
System.out.println("The names are :");
for(i=0;i<5;i++)
System.out.println(m[i]);
}
}
Output:
The names are :
Anith
Ben
Rajiv
Vijay
Zafa
Output:
Enter number of array elements arr1
3
Enter number of array elements arr2
4
Enter number of elements in merged array arr3
7
Enter elements in array arr1
1
2
3
Enter elements in array aar2
4
5
6
7
Array elements after merging
1
2
3
4
5
6
7
Output:
40
c
W
W*lcom*! to Sathyabama univ*rsity Plan*t
Output:
The substring from 5th position = standing
The substring from 5th index and excluding 10th index=stand
The first position of the character m =2
The position of 'm' from 5th character = 8
The compare string = -32
The comparing strings after ignoring case= 0
The comparison using equals ignore case= true
The reversed string= ESOB ARDNAHC HSABUS
class Armstrong
{
public static void main(String arg[])
{
int a,num,s=0,n=371;
num=n;
while(n>0)
{
a=n%10;
s=s+a*a*a;
n=n/10;
}
if(num==s)
System.out.println("The number" + num +"is an Armstrong Number");
else
System.out.println("The number" + num +"is not an Armstrong Number");
}
}
Output:
The Number 371 is an Armstrong number
import java.util.*;
class Menu
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int c,s,a,b,m=0,n=0,p=0;
double k, area=0;
System.out.println("l. Area of an Equilateral Triangle");
System.out.println("2. Area of an Isosceles Triangle");
System.out.println("3. Area of a Scalene Triangle");
System.out.println("Enter your choice");
c=in.nextInt();
switch(c)
{
case 1:
System.out.println("Enter side of an Equilateral triangle");
s=in.nextInt();
area= (Math.sqrt(3)*s*s)/4.0;
System.out.println(" Area =" +area);
break;
case 2:
System.out.println("Enter side and base of Isosceles Triangle");
a=in.nextInt();
b=in.nextInt();
area=b*(Math.sqrt(4*a*a-b*b))/4.0;
System.out.println(" Area =" +area);
break;
case 3:
System.out.println("Enter side of Scalene Triangle");
m=in.nextInt();
n=in.nextInt();
k=(m+n+p)/2.0;
area=Math.sqrt(k*(k-m)*(k-n)*(k-p));
System.out.println(" Area =" +area);
break;
default:
System.out.println("Wrong Choice!!");
}
}
}
Output:
l. Area of an Equilateral Triangle
2. Area of an Isosceles Triangle
3. Area of a Scalene Triangle