generating Piglatin: Output
generating Piglatin: Output
generating Piglatin: Output
*;
class WordPig
{
public static void main (String args[])
{
Scanner sc = new Scanner ( System.in );
System.out.println("Enter a word ");
String str = sc.nextLine();
//generating piglatin
int i;
int l = str.length();
String w = "";
for(i=0;i<l;i++)
{
char c = str.charAt(i);
if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||
c=='U')
break;
else
w=w+c;
}
System.out.println("Piglatin of :"+str+" = "+str.substring(i,l)+w+"ay");
}
}
Output:
Enter a word
trouble
Piglatin of: trouble = oubletray
import java.util.*;
class PrimePalNum
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter lower limit for range ::");
int l = sc.nextInt();
System.out.println("Enter upper limit for range ::");
int u = sc.nextInt();
//generating prime palindromic numbers
for (int i=l;i<=u;i++)
{
if(isprime(i)==true&& ispal(i)==true)
System.out.print(i+" ; ");
}
}
static boolean isprime(int i)
{
boolean flag = true ;
for(int j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag = false;
break;
}
}
return flag;
}
static boolean ispal(int i)
{
int rev =0,d,copy =i;
while(copy>0)
{
d=copy%10;
rev=(rev*10)+d;
copy/=10;
}
if(rev==i)
return true;
else
return false;
}
}
Output:
Enter lower limit for range ::
10
Enter upper limit for range ::
200
11 ; 101 ; 131 ; 151 ; 181 ; 191 ;
import java.util.*;
class RevSent
{
import java.util.*;
class Insert
{
Output:
Enter length of array
4
Enter 4 numbers into the array
3
7
9
6
Original array ::
3,7,9,6,
Enter number to be inserted
8
Enter position where 8 is to be inserted
2
Final array ::
3,7,8,9,6,
import java.util.*;
class Delete
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter size of array");
int len = sc.nextInt();
int a[] =new int[len];
Output:
Enter size of array
4
Enter 4 numbers into the array
9
3
5
2
Original array ::
9,3,5,2,
Enter number to be deleted
3
Final array ::
9,5,2,
import java.util.*;
class Weakarm
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter number");
int n= sc.nextInt();
int copy=n,d,c=1,rev=0;
double s =0.0;
while(copy>0)
{
d=copy%10;
rev=rev*10+d;
copy/=10;
}
while(rev>0)
{
d=rev%10;
s=s+Math.pow(d,c++);
rev/=10;
}
if((int)s==n)
System.out.println(n+"is Weakarm");
else
System.out.println(n+"is not Weakarm");
}
}
Output:
Enter number
135
135 is Weakarm
Enter number
987
987 is not Weakarm
import java.util.*;
class PrimeFibo
{
public static void main(String args[])
{
Output:
Enter lower limit and upper limit
10
200
Prime fibonacci numbers are ::
21
34
55
144
import java.io.*;
class Insertion_Sort
{
void main(String args[])
throws IOException
{
//Insertion Sort
Output:
How many elements ?
4
Enter 4 elements into array
7
8
6
3
Original Array
7863
Sorted array
3678
import java.util.*;
class AreaOverload
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("1.Area of triangle");
System.out.println("2.Area of square");
System.out.println("3.Area of rectangle");
System.out.println("4.Area of circle");
System.out.println("5.Exit");
System.out.println("Enter choice");
int ch = sc.nextInt();
switch(ch)
{
case 1 :System.out.println("Enter base and height");
double b = sc.nextDouble();
double h = sc.nextDouble();
Area(b,h);
break;
case 2 :System.out.println("Enter length of side");
int s = sc.nextInt();
Area(s);
break;
case 3:System.out.println("Enter length and breadth");
int l = sc.nextInt();
int br = sc.nextInt();
Area(l,br);
break;
case 4:System.out.println("Enter radius");
double r = sc.nextDouble();
Area(r);
break;
case 5:break;
default : System.out.println("Wrong Choice");
}
}
class Sample_Angle
{
public void main()
{
Angle A = new Angle (34,45);
Angle B = new Angle (32,25);
Angle C = new Angle(0,0);
System.out.println("Angle A =");
A.display();
System.out.println("Angle B =");
B.display();
C=C.add(A,B);
System.out.println("Angle C =");
C.display();
}
}
class Angle
{
private int x,y;
Angle()
{
x=0;
y=0;
}
Angle(int a, int b)
{
x=a;
y=b;
}
public void display()
{
System.out.println(x+" degrees "+y+" minutes ");
}
public Angle add(Angle A,Angle B)
{
Angle C = new Angle(0,0);
C.y=A.y+B.y;
if(C.y>60)
{
C.y-=60;
C.x=A.x+B.x+1;
}
else
C.x=A.x+B.x;
return C;
}
}
Output :
Angle A =
34 degrees 45 minutes
Angle B =
32 degrees 25 minutes
Angle C =
67 degrees 10 minutes