23CY201-JavaProgramming-CIA1-Answerky.docx
23CY201-JavaProgramming-CIA1-Answerky.docx
Regulation – 2022
Question Instructions:
13. i) Danny has recently got his job offer as an Event Concept
Creator at Sparsh Event Services. The Company has sent him
a detailed salary structure with details of his basic salary,
HRA and DA. The Company has promised to pay him as
under: AP C201.2 16
If his basic salary is less than Rs. 15000, then HRA = 15% of
basic salary and DA = 90% of basic salary.
If his basic salary is either equal to or above Rs. 15000, then
HRA = Rs. 5000 and DA = 98% of basic salary.
Note : Gross Salary = Basic Salary+HRA+DA
Sample Input
12000
Sample Output
24600.00
15. i) Write a java program to generate the first 'n' terms of the
following series 1, 2, 3, 6, 9, 18, 27,...
Sample Input
6
Sample Output
1 2 3 6 9 18
AP C201.3 16
import java.util.*;
class main
{
public static void main(String args[])
{
Scanner t=new Scanner(System.in);
int n=t.nextInt();
int a=1,b=2,sum;
System.out.print(a+" "+b+" ");
for(int i=3;i<=n;i++)
{
if(i%2!=0)
{
sum=a+b;
System.out.print(sum+" ");
}
else
{
sum=b*2;
System.out.print(sum+" ");
}
a=b;
b=sum;
}
}
}
OR
16. i) The factorial concept was explained in Seetha's math class.
Ankit discovered a connection between the sum of the
factorial of digits in a number and the number itself when
experimenting with numbers after understanding the idea of
factorial. He began looking for additional numbers like this
since he was so excited. Write a suitable Java program to
check the supplied numbers to aid Ankit.
Explanation:
Input:
145
Output:
145 Strong Number AP C201.3 16
In this case, the program reads the input integer 145 and
calculates the factorial of each digit of the number (1! + 4! +
5!). It then checks if the sum of the factorials is equal to the
original number, which is true for 145, so the program prints
"145 Strong Number" on the console as the output.
Sample Input
145
Sample Output
145 Strong Number
Sample Input
5
Sample Output
1 1
2 2
3 3
44
5
4 4
3 3
2 2
1 1
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int rows=sc.nextInt();
int i,j,col=0;
col=(rows*2)-1;
for(i=1;i<=rows;i++)
{
for(j=1;j<=col;j++)
{
if(j==i)
{
System.out.print(i);
}
else if(j==col)
{
System.out.print(i);
}
else { System.out.print(" ");}
if (j<=col){
System.out.print(" ");}
}
col--;
System.out.println();
}
col+=2;
for(i=rows-1;i>=1;i--)
{
for(j=1;j<=col;j++)
{
if(j==i)
{
System.out.print(i);
}
else if(j==col)
{
System.out.print(i);
}
else { System.out.print(" ");}
if (j<=col){
System.out.print(" ");}
}
col++;
System.out.println();
}
sc.close();
}
}
int n = scanner.nextInt();
scanner.close();
}
}
OR
20. i) Johnsy wants to create a matrix in which the elements are
formed differently. The elements are formed by adding the
values of their index positions. Write a program that obtains
the order of the matrices and creates a matrix by adding the
values of their index positions.
Sample Input
33
Sample Output
0 1 2
1 2 3
2 3 4
}
}