Comp PRP 2
Comp PRP 2
WAP to create two arrays of integer type of size 5 and store the sum of both
the arrays in third array C
import java.util.Scanner;
class xyz {
A[i] = sc.nextInt();
B[i] = sc.nextInt();
System.out.println("printing [i]");
System.out.println( C[i]);
}
OUTPUT
}
System.out.println("printing sorted array");
for (int j = 0; j<=9; j++){
System.out.println( A[j]);
}
}
}
OUTPUT
import java.util.Scanner;
class merging {
public static void main() {
Scanner sc = new Scanner(System.in);
int A []= new int [5] ;
int B []= new int [5] ;
int C []= new int [10] ;
System.out.println("Enter elements");
for(int i = 0; i<5; i++) {
A[i] = sc.nextInt();
B[i] = sc.nextInt();
}
for(int i = 0; i<5; i++) {
C[i] = A[i];
C[i+5 ] = B[i];
}
System.out.println("Printing C" );
for(int i = 0; i<10; i++) {
System.out.println(C[i]);
}
}
}
OUTPUT
import java.util.Scanner;
class abc {
public static void main() {
Scanner sc = new Scanner(System.in);
int A [][]= new int [3][3] ;
System.out.println("Enter elements");
import java.util.Scanner;
class diagonalarray {
public static void main() {
Scanner sc = new Scanner(System.in);
int A [][]= new int [4][4] ;
System.out.println("Enter elements");
int rtd = 0, ltd = 0;
for(int i = 0; i<4; i++) {
for(int j = 0; j<4; j++) {
A[i][j] = sc.nextInt(); }}
for(int i = 0; i<4; i++) {
for(int j = 0; j<4; j++) {
if ( i == j){
ltd= ltd + A[i][j];
System.out.println("Sum of left diagonal "+ ltd);}
if((i+j)==3){
rtd = rtd+A[i][j];
System.out.println("sum of right diagonal "+ rtd );}}
if(ltd == rtd)
System.out.println("An array is diagonal");
else
System.out.println("An array is not diagoanl");
}}}
OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
A[][] int To store
elements of
the array
i int Counter
variable
j int Counter
variable
ltd int To store the
sum of left
diagonal
elements
rtd int To store the
sum of right
diagonal
elements
6.WAP to input a number and check whether if it is a pronic number or not.
class pronic
{
public static void main(int n)
{
int c = 0;
for( int i = 0; i<=n; i++)
{
if(n==i*(i+i))
{
c++;
break;
}}
if(c>0)
System.out.println(n + " is a pronic number");
else
System.out.println(n + " is not a pronic number");
}
}
OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
n int To store a number
c int Counter variable to
check whether a
number is a pronic
number or not
i int Counter variable
class palindrome
{
public static void main(int n)
{
int x = n;
int rev = 0;
while(x>0)
{
int d = x%10;
rev= rev * 10+d;
x = x/10;
}
if(rev == n)
System.out.println(n + " is a palindrome number");
else
System.out.println(n + " is not a palindrome number");
}
}
OUTPUT
class armstrong
{
public static void main(int n)
{
int x = n;
int sum = 0;
while(x>0)
{
int d = x%10;
sum = sum + (d*d*d);
x = x/10; }
if(sum == n)
System.out.println(n + " is an armstrong number");
else
System.out.println(n + " is not an armstrong number");
}
}
OUTPUT
import java.util.Scanner;
class taximeter {
int km,bill,taxinumber;
String name;
taximeter() {
km= 0;
bill = 0;
taxinumber = 0;
name = " "; }
void input () {
Scanner sc = new Scanner(System.in);
System.out.println(" input details");
km = sc.nextInt() ;
taxinumber = sc.nextInt();
name = sc.next(); }
void calculate() {
if(km<=1)
bill = 25;
else if ( km>1 && km <=6)
bill = km * 10;
else if (km >6 && km<=12)
bill = km * 15;
else if ( km>12 && km<= 18)
bill = km * 20;
else
bill = km * 25; }
void display() {
System.out.println("Name = " + name);
System.out.println("Taxinumber = " + taxinumber);
System.out.println("km travelled = " + km);
System.out.println("bill= " + bill); }
void main() {
taximeter ob = new taximeter ();
ob.input();
ob.calculate();
ob.display();
}
OUTPUT
amount = 0.0;
name = " "; }
void input () {
Scanner sc = new Scanner(System.in);
System.out.println(" input details");
cost = sc.nextDouble();
name = sc.next(); }
void calculate() {
if(cost<=10000)
discount = 0.05 * cost;
else if ( cost>10000 && cost<=20000)
discount = 0.10 * cost;
else if (cost >20000 && cost<=35000)
discount = 0.15 * cost;
else
discount = 0.20* cost;
amount = cost - discount; }
void display() {
System.out.println("Name = " + name);
System.out.println("cost = " + cost);
System.out.println("Discount = " + discount);
System.out.println("Amount= " + amount); }
void main() {
showroom ob = new showroom ();
ob.input();
ob.calculate();
ob.display();
}}
OUTPUT
VARIABLE DESCRIPTION TABLE
VARIABLE DATA TYPE PURPOSE
name String To store name
cost double To store cost
discount double To store discount
amount double To store the total
amount