BCSE103E-Computer programming java
Assignment-1
Student Name: DAGUMATI HARSHA VARDHAN
Student ID: 21BCE2879
Lab Slot: L19+L20
Date of Submission: 16/9/2022
21BCE2879
1. ABC company Ltd. is interested to computerize the pay
calculation of their employee in the form of Basic Pay,
Dearness Allowance (DA) and House Rent Allowance (HRA).
DA and HRA are calculated as certain % of Basic pay(For
example, DA is 80% of Basic Pay, and HRA is 30% of Basic
pay). They have the deduction in the salary as PF which is 12%
of Basic pay. Propose a computerized solution for the above
said problem.
Code:
import java.util.*;
public class Programss
public static void main(String args[])
Scanner input=new Scanner(System.in);
System.out.println("Enter the basic pay");
double bas=input.nextDouble();
double DA=bas*0.8;
double HRA=bas*0.3;
double PF=bas*0.12;
double salary=bas+DA+HRA-PF;
System.out.println("Salary="+salary);
21BCE2879
}
Code screenshot:
Output screenshot:
21BCE2879
2. Get the five digit number from the user as the input and write a
menu driven program to perform the following:
Option: calculate the sum of its digits. (Hint: Use the modulus
operator‘%’)
Option2: to reverse the number.
Option3: to obtain the sum of the first and last digit of this
number.
Option4: to find the count of odd and even numbers in the given
input
Code:
import java.util.*;
public class Programss
public static void main(String args[])
Scanner input=new Scanner(System.in);
System.out.println("Enter a number");
int a=input.nextInt();
System.out.println("Enter 1: calculate the sum of its digits.");
System.out.println("Enter 2: to reverse the number.");
System.out.println("Enter 3: to obtain the sum of the first and last digit of this
number.");
System.out.println("Enter 4: to find the count of odd and even numbers in the given
input");
System.out.println("Enter your choice");
int b=input.nextInt();
switch(b)
21BCE2879
{
case 1:
int number=a;
int sum=0;
while(number > 0)
int digit = number%10;
sum = sum+digit;
number = number / 10;
System.out.println("sum="+sum);
break;
case 2:
int number1=a;
int reverse=0;
while(number1>0)
int remainder = number1%10;
reverse = reverse*10+remainder;
number1 = number1/10;
System.out.println("The reversed number="+reverse);
break;
21BCE2879
case 3:
int number2=a;
int c=5;
int sum1=0;
while(number2>0)
int f=number2%10;
if((c==5)||(c==1))
sum1=sum1+f;
c--;
number2=number2/10;
System.out.println("The sum of last and first digit="+sum1);
break;
case 4:
int number3=a;
int c1=0;
int c2=0;
while(number3>0)
int g=number3%10;
if(g%2==0)
21BCE2879
{
c1++;
else if(g%2!=0)
c2++;
number3=number3/10;
System.out.println("The number of even digits in the number="+c1);
System.out.println("The number of odd digits in the number="+c2);
break;
default:
System.out.println("Invalid input");
21BCE2879
Code screenshot:
21BCE2879
Output screenshot:
21BCE2879
21BCE2879
21BCE2879
3. Write aJava program to delete the numbers divisible by 5 from
an array.
Code:
import java.util.*;
public class Programss
public static void main(String[] args)
int [] arr;
int n=0,i=0,j=0,k=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter size of array");
n = sc.nextInt();
arr=new int[n];
System.out.println("Enter numbers in array");
for(i=0;i< n;i++)
arr[i]=sc.nextInt();
}
21BCE2879
for(i=0;i< n;i++)
if(arr[i]%5==0)
k=i;
for(j=k+1;j< n;j++)
arr[k]=arr[j];
k++;
i=0;
n=n-1;
System.out.println("array after deleting ");
for(i=0;i< n;i++)
System.out.print(arr[i]+" ");
21BCE2879
}
Code screenshot:
21BCE2879
Output screenshot:
21BCE2879