You are on page 1of 3

Make a copy of this file and answer on the document itself.

You can try out these in java and


then copy paste the answers here.
Once done convert your answer file to pdf and submit it in the ManageBac.
Answer the following questions in the context of Java programming

1. Find the largest and smallest byte, short, int, long, float, and double. Which of these
data types requires the least amount of memory? byte

2. Show the result of the following remainders:


a. 56 % 6 =2
b. 78 % -4 = 2
c. -34 % 5 = -4
d. -34 % -5 = 4
e. 5%1 =0
f. 1%5 = 1
public class cshw {
public static void main(String[] args) {
System.out.println("1%5=" + (1%5));
}
}

3. What is the result of 25 / 4? How would you rewrite the expression if you wished the
result to be a floating-point number?
6,
public class cshw {
public static void main(String[] args) {
System.out.println("25/4=" + (25.0/ 4));

}}

4. Show the result of the following code:


a. System.out.println(2 * (5 / 2 + 5 / 2));
8
public class cshw {
public static void main(String[] args) {
System.out.println((2 * (5 / 2 + 5 / 2)));
}

}
Output:
C:\Users\cheri\.jdks\openjdk-17.0.1\bin\java.exe
"-javaagent:C:\Users\cheri\OneDrive\Desktop\IntelliJ IDEA Community Edition
2021.2.3\lib\idea_rt.jar=61740:C:\Users\cheri\OneDrive\Desktop\IntelliJ IDEA Community
Edition 2021.2.3\bin" -Dfile.encoding=UTF-8 -classpath
C:\Users\cheri\IdeaProjects\Cshw\out\production\Cshw cshw
8

Process finished with exit code 0


b. System.out.println(2 * 5 / 2 + 2 * 5 / 2);
10
public class cshw {
public static void main(String[] args) {
System.out.println(2 * 5 / 2 + 2 * 5 / 2);
}
}
c. System.out.println(2 * (5 / 2));
4
public class cshw {
public static void main(String[] args) {
System.out.println(2 * (5 / 2));
}
}

d. System.out.println(2 * 5 / 2);
5
public class cshw {
public static void main(String[] args) {
System.out.println(2 * 5 / 2);
}
}
5. Write a program that converts a Fahrenheit degree to Celsius using the formula
5
Celsius = ( 9 )(Fahrenheit - 32)

public class cshw {


public static void main(String[] args) {
double tempFahrenheit=98;
double celsius;
celsius = ((5.0 / 9) * (tempFahrenheit - 32));
System.out.println("It is " + celsius + " celsius.");

}
6. Write a program to calculate the circumference of a circle.
import static java.lang.System.*;

public class cshw {


public static void main(String[] args) {
double radius=5;
final double PI= 3.14;
double circumference = (2 * (PI)*radius);
System.out.println("The circumference is " + circumference + " cm.");

}
7. Write a program to find the area of a triangle.
import static java.lang.System.*;

public class cshw {


public static void main(String[] args) {
double base=5;
double height= 10;
double area = (1.0/2 * (base)*height);
System.out.println("The area of the triangle is " + area + " cm
squared.");

}
8. Write a program to assign 5 subject marks of a student and calculate the total and
average marks.
public class cshw {
public static void main(String[] args) {
int mark1 = 100;
int mark2 = 73;
int mark3 = 34;
int mark4 = 99;
int mark5 = 85;
double total = mark1+mark2+mark3+mark4+mark5;
double average = total/5;
System.out.println("The total is " + (total) + ".");
System.out.println("The average for the 5 students is " + average);

Numeric Data types in Java: Reference

You might also like