Java Exercise-1
Java Exercise-1
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
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));
}}
}
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
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)
}
6. Write a program to calculate the circumference of a circle.
import static java.lang.System.*;
}
7. Write a program to find the area of a triangle.
import static java.lang.System.*;
}
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);