Roll No.
- MCA/10071/24
Date – 8/13/2024
Q1> Write a program to print your name, roll no, section and branch
in separate lines
Q2> Write a program in Java to take first name and last name from the user and
print both in one line as last name followed by first name.
Q3> Make a program to make a multiplication table as shown
Q4> Write a program to calculate area for circle. Take input at run time.
Q5> Write a program to calculate area for square. Take input at run time.
Q6> Write a program to calculate area for triangle. Take input at run time.
Q7> Write a program to calculate area for rectangle. Take input at run time.
Bonus 1> Write a program to input a number and find its 1's complement and 2's
complement of the number.
Bonus 2> Write a program to input a decimal number and find its hexadecimal
value.
Bonus 3> Write a program to find the bytes of all the primitive datatypes.
Q1 - Write a program to print your name, roll no, section and branch
in separate lines
/*
8/13/2024
Q> Write a program to print your name, roll no, section and branch
in separate lines **/
import [Link].*;
public class Main {
public static void main(String[] args) {
String name = "",roll_no = "", section = "", branch ="";
Scanner sc = new Scanner([Link]);
[Link]("Input your name: ");
name = [Link]();
[Link]("Input your roll number: ");
roll_no = [Link]();
[Link]("Input your section: ");
section = [Link]();
[Link]("Input your branch: ");
branch = [Link]();
[Link]("Your details are as follows: ");
[Link]("Name: " + name);
[Link]("Roll. No.: " + roll_no);
[Link]("Section: " + section);
[Link]("Branch: " + branch);
}
}
OUTPUT
Q2 - Write a program in Java to take first name and last name from the user and
print both in one line as last name followed by first name.
import [Link];
/*
8/13/2024
Write a program in Java to take first name and last name from the user and
print both in one line as
last name followed by first name.
*/
public class Main {
public static void main(String[] args) {
String first = "",last = "";
Scanner sc = new Scanner([Link]);
[Link]("Input your first name: ");
first = [Link]();
[Link]("Input your last name: ");
last = [Link]();
[Link]("Your name is as follows: ");
[Link]("Name: " + last + " " + first);
}
}
OUTPUT
Q3 - Make a program to make a multiplication table as shown
/*
8/13/2024
Make a program to make a multiplication table as shown
*/
public class Main {
public static void main(String[] args) {
[Link]("Multiplication table is as follows: ");
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= 5; j++) {
[Link](i*j+"\t");
}
[Link]();
}
}
}
OUTPUT
Q4 - Write a program to calculate area for circle. Take input at run time.
/*
8/13/2024
Write a program to calculate area for circle. Take input at run time.
*/
import [Link];
public class Main {
private double area(int a){
return (22*a*a)/7;
}
public static void main(String[] args) {
double result = 0.0;
int a = 0;
Main obj = new Main();
Scanner sc= new Scanner([Link]);
[Link]("Input the radius of the circle: ");
a = [Link]();
result = [Link](a);
[Link]("Area: " + result + " unit(s) sq.");
}
}
OUTPUT
Q5 - Write a program to calculate area for square. Take input at run time.
/*
8/13/2024
Write a program to calculate area for square. Take input at run time.
*/
import [Link];
public class Main {
private double area(int a){
return (a*a);
}
public static void main(String[] args) {
double result = 0.0;
int a = 0;
Main obj = new Main();
Scanner sc= new Scanner([Link]);
[Link]("Input the side of the square: ");
a = [Link]();
result = [Link](a);
[Link]("Area: " + result + " unit(s) sq.");
}
}
OUTPUT
Q6 - Write a program to calculate area for triangle. Take input at run time.
/*
8/13/2024
Write a program to calculate area for triangle. Take input at run time.
*/
import [Link];
public class Main {
private double area(int a, int b, int c){
double s = (a + b + c)/2;
return [Link](s*(s-a)*(s-b)*(s-c));
}
public static void main(String[] args) {
double result = 0.0;
int a = 0, b = 0, c = 0;
Main obj = new Main();
Scanner sc= new Scanner([Link]);
[Link]("Input the first side of the triangle: ");
a = [Link]();
[Link]("Input the second side of the triangle: ");
b = [Link]();
[Link]("Input the third side of the triangle: ");
c = [Link]();
result = [Link](a, b, c);
[Link]("Area: " + result + " unit(s) sq.");
}
}
OUTPUT
Q7 - Write a program to calculate area for rectangle. Take input at run time.
/*
8/13/2024
Write a program to calculate area for rectangle. Take input at run time.
*/
import [Link];
public class Main {
private double area(int a, int b){
return (a * b);
}
public static void main(String[] args) {
double result = 0.0;
int a = 0, b = 0;
Main obj = new Main();
Scanner sc= new Scanner([Link]);
[Link]("Input the length of the rectangle: ");
a = [Link]();
[Link]("Input the breath of the rectangle: ");
b = [Link]();
result = [Link](a, b);
[Link]("Area: " + result + " unit(s) sq.");
}
}
OUTPUT
BONUS 1 - Write a program to input a number and find its 1's complement and
2's complement of the number.
/*
8/13/2024
Write a program to input a number and find its 1's complement and 2's
complement of the number.
*/
import [Link];
public class Main {
private double area(int a){
return (a*a);
}
public static void main(String[] args) {
int a = 0;
String b ="", c = "";
Scanner sc= new Scanner([Link]);
[Link]("Input a number: ");
a = [Link]();
if(a<0){
b = [Link](-a);
while ([Link]() < 32) {
b = "0" + b;
}
for(int i=0 ; i < [Link]() ; i++){
c += ([Link](i) == '0') ? '1' : '0';
}
[Link]("1's complement: " + c);
}else{
[Link]("1's complement: " +
[Link](a));
}
[Link]("2's complement: " + [Link](a));
}
}
OUTPUT
BONUS 2 - Write a program to input a decimal number and find its
hexadecimal value
/*
8/13/2024
Q> Write a program to covert a decimal number to its hexadecimal value
*/
import [Link];
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a decimal number:");
int decimal = [Link]();
String hexadecimal = [Link](decimal).toUpperCase();
[Link]("The hexadecimal equivalent is: " +
hexadecimal);
[Link]();
}
}
OUTPUT
BONUS 3 - Write a program to find the size of all the primitive datatypes
/*
8/13/2024
Q> Write a program to find the size of all the primitive datatypes
*/
public class Main {
public static void main(String[] args) {
[Link]("Size of byte: " + [Link] + " bytes");
[Link]("Size of short: " + [Link] + " bytes");
[Link]("Size of int: " + [Link] + " bytes");
[Link]("Size of long: " + [Link] + " bytes");
[Link]("Size of float: " + [Link] + " bytes");
[Link]("Size of double: " + [Link] + " bytes");
[Link]("Size of char: " + [Link] + " bytes");
[Link]("Size of boolean: " + "JVM dependent");
}
}
OUTPUT