Sie sind auf Seite 1von 11

import java.util.

*;
class patt
{
public static void main(String[] args)
{
int r,c;
for(r=1;r<=5;r++)
{
for(c=1;c<=r;c++)
{
System.out.print(" "+c);
}
System.out.println();
}
}
}

import java.util.*;
class patt
{
public static void main(String[] args)
{
int r,c;
for(r=1;r<=5;r++)
{
for(c=1;c<=r;c++)
{
System.out.print(" "+r);
}
System.out.println();
}
}
}

import java.util.*;
class patt
{
public static void main(String[] args)
{
int r,c;
for(r=1;r<=5;r++)
{
for(c=1;c<=r;c++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}

Question :- WAP to enter principle,rate and time .Calculate the simple Interest and
Compound Interest
import java.util.*;
class patt
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double p,r,t,si,ci;
System.out.print("Enter principle amount ");
p=sc.nextDouble();
System.out.print("Enter rate of interest ");
r=sc.nextDouble();
System.out.print("Enter rate of Time
");
t=sc.nextDouble();
si=(p*r*t)/100;
ci= p+Math.pow((1+r/100),t)-p;
System.out.println("Simple Interest
"+si);
System.out.println("Compound Interest "+ci);
}
}

Question : WAP to enter number from user and print it factorial


import java.util.*;
class factorial
{
public static int fact(int num)
{
int i,f=1;
for(i=1;i<=num;i++)
{
f=f*i;
}
return(f);
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n,x=0;
System.out.print("Enter number ");
n=sc.nextInt();
x=fact(n);
System.out.println("Factorial of a given number
}
}

"+x);

WAP a program to find Area and perimeter of a rectangle


import java.util.*;
class peri
{
public static void area(float len,float breat)
{
float area=0;
area = len * breat;
System.out.println("Area of rectangle is "+area);
}
public static void perimeter(float len,float breat)
{
float peri=0;
peri = 2*(len + breat);
System.out.println("Perimeter of rectangle is "+peri);
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
float a,b;
System.out.print("Enter length ");
a=sc.nextFloat();
System.out.print("Enter length ");
b=sc.nextFloat();
area(a,b);;
perimeter(a,b);
}
}

Create an array of 10 elements and find sum of all element


import java.io.*;
class array
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
int n[] = new int[10];
int i,sum=0;
for(i=0;i<=9;i++)
{
System.out.print("Enter number of array ");
n[i]=Integer.parseInt(br.readLine());
}
for(i=0;i<=9;i++)
{
System.out.print("\n "+n[i]);
sum=sum+n[i];
}
System.out.println("\n Sum of all element
}
}

"+sum);

Create an array of 10 numbers and find frequency of a given number


import java.io.*;
class array
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n[] = new int[10];
int i,f=0,num;
for(i=0;i<=9;i++)
{
System.out.print("Enter number of array ");
n[i]=Integer.parseInt(br.readLine());
}
System.out.print("Enter element to b searched
num=Integer.parseInt(br.readLine());
for(i=0;i<=9;i++)

");

{
System.out.print("\n "+n[i]);
if(num==n[i])
f++;
}
System.out.println("\n frequency of a given number is

}
}

"+f);

Create two arrays of 10 element and find sum of both array in third array
import java.io.*;
class array
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n[] = new int[10];
int m[] = new int[10];
int s[] = new int[10];
int i;
for(i=0;i<=9;i++)
{
System.out.print("Enter number of first array ");
n[i]=Integer.parseInt(br.readLine());
}
for(i=0;i<=9;i++)
{
System.out.print("Enter number of second array ");
m[i]=Integer.parseInt(br.readLine());
}
for(i=0;i<=9;i++)
{
s[i]=n[i]+m[i];
System.out.print("\n "+n[i]+"\t"+m[i]+"\t"+s[i]);
}
}
}

Create an array of 10 elements and print it in reverse order


import java.io.*;
class array
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
int n[] = new int[10];
int i;
for(i=0;i<=9;i++)
{
System.out.print("Enter number of first array
n[i]=Integer.parseInt(br.readLine());
}
for(i=9;i>=0;i--)
{
System.out.print("\n "+n[i]);
}
}
}

");

Das könnte Ihnen auch gefallen