AtharvNayak_9A_ComputerProject
AtharvNayak_9A_ComputerProject
Programming in Java
Arya Nanjayan
INDEX
Program-01 Program to find the sum and product of the fractional numbers 2, 3
Program to find the sum and product of first and last digits of a 10, 11
Program-06
three-digit number of a long integer type
1
PROGRAM-01
Question-
Write a program to initialise fractional numbers 7.6,3.2,6.4. Print the sum and product of the numbers
Answer-
sum = x+y+z;
product = x*y*z;
}//main
}//class
2
Output-
3
PROGRAM-02
Question-
Write a program to print the quotient and remainder of integer 187 by integer 13.
Answer-
}//main
}//class
Output-
4
PROGRAM-03
Question-
Write a program to assign integers a, b, c with values 3,6,9. Perform, the operations and print the
results of the operations: S=(a+b+c)/2 and V=(a2+b2)/c3
Answer-
int a = 3, b = 6, c = 9;
System.out.println("Value of S- "+S);
System.out.println("Value of V- "+V);
5
Output-
6
PROGRAM-04
Question-
Write a program to accept Principal amount(P), rate of interest (R) and Time (T) through
parameterized method. Calculate and print the Simple Interest.
Answer-
}//main
}//class
Output-
7
PROGRAM-05
Question-
Write a program to accept values for variables a and b through parameterized method. Swap their
values using third variable. Display the values after swapping.
Answer-
System.out.println("a is "+a);
System.out.println("b is "+b);
System.out.println("-----------");
//swapping
int temp = a;
a = b;
b = temp;
System.out.println("a is "+a);
System.out.println("b is "+b);
}//main
}//class
8
Variable description table-
Output-
9
PROGRAM-06
Question-
8,9Write a program to initialize a three-digit number of a long integer type. Print the sum and product
of first and last digits of that number.
Answer-
import java.util.*;
long a = sc.nextLong();
long n1 = a/100;
long n3 = ((a%100)%10);
System.out.println("Sum of first and last digit is- " + (n1+n3) + "\nProduct of first and last digit is-
" + (n1*n3));
}//main
}//class
10
temp int For temporarily storing value of
a
Output-
11
PROGRAM-07
Question-
Create a class Student_Info to input (Scanner method) marks in English, Maths, Physics, Chemistry,
Biology, Computer Applications. Print the marks obtained in all the subjects, total marks and
percentage. (Assume that the maximum mark in each subject is 100)
Answer-
import java.util.*;
12
System.out.println("--------------");
percentage earned
//output
System.out.println("Percentage- "+percent);
}//main
}//class
13
chemistry
14
bio int For storing marks obtained in
biology
comp
int For storing marks obtained in
computer application
totalMarks
double For storing total marks obtained
Output-
15
PROGRAM-08
Question-
Write a program to input three sides of a triangle (Scanner method). Print the area of the triangle
using the given formula. The class name is Triangle. (Area=√𝑠(𝑠−𝑎)(𝑠−𝑏)(𝑠−𝑐)
Answer-
import java.util.*;
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
}//main
}//class
16
Variable description table-
Output-
17
PROGRAM-09
Question-
Write a program to which inputs two integers num1, num2 and operator, that contains an arithmetic
operator (‘+’, ‘--‘, ‘/’ or ‘*’) only. Perform and print the corresponding operation on n1 and n2 on the
basis of the operator using the switch--case or user’s choice statement. For example if n1=6,n2=3
and operator=’*’, then result will be n1*n2=6*3=18 similarly for other operations.
Answer-
import java.util.*;
double ans=0;
double n1 = sc.nextDouble();
double n2 = sc.nextDouble();
char ch = sc.next().charAt(0);
switch (ch)
case '+':
ans = n1+n2;
18
break;
case '-':
ans = n1-n2;
break;
case '*':
ans = n1*n2;
break;
case '/':
ans = n1/n2;
break;
default:
System.out.println("Invalid choice");
}//switch-case
}//main
}//class
19
Output-
20
PROGRAM-10
Question-
An XYZ mall has announced the festive discounts on the purchase of items based on the total cost of
items as per the given criteria.
25001-30000 7% 10%
Write a program to input the name of the customer, total cost of purchase, type of the purchase (H for
Home Appliances and F for Furniture) using Scanner class. Compute and display the amount to be
paid by the customer after availing the discount
Answer-
import java.util.*;
System.out.print("Enter type of purchase(H for home appliances and F for furniture)- ");
char ch = sc.next().charAt(0);
21
switch (ch)
case 'H':
if (cost <=25000)
break;
case 'F':
if (cost <=25000)
break;
default:
System.out.println("Invalid choice!");
22
}//switch-case
System.out.println("Name- "+name);
}//main
}//class
Output-
23
24