0% found this document useful (0 votes)
15 views

Test 1 AAns

The document describes how to create a flowchart to compare two input values (A and B), determine which is greater, check if the greater value is even, and print the even value. It includes symbols to represent inputs, processes, decisions, and outputs, and describes how to connect them with arrows to show the flow.

Uploaded by

tukma2kov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Test 1 AAns

The document describes how to create a flowchart to compare two input values (A and B), determine which is greater, check if the greater value is even, and print the even value. It includes symbols to represent inputs, processes, decisions, and outputs, and describes how to connect them with arrows to show the flow.

Uploaded by

tukma2kov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

var A

1. 1.c
2.a
3.b
4.a
5.a
6.c
7.d
2. art: Use the oval symbol to indicate the start of the flowchart.
Input: Use the parallelogram symbol to represent input. Label it "Input A" to indicate the
first positive integer.
Input: Another parallelogram symbol for the second input. Label it "Input B."
Process: Use a rectangle to represent a process. In this rectangle, compare the values of A
and B to determine which is greater. Use a decision diamond (diamond-shaped symbol) with
conditions like "A > B?" and "B > A?" to decide the flow.
Decision: Based on the comparison result, follow arrows to the next steps. If A is greater,
move to the next step; if B is greater, follow the other arrow.
Process: Another rectangle to check if the greater value is even. Use a decision diamond
with a condition like "Is it even?" to decide the flow.
Decision: Based on the even/odd result, follow arrows. If it's even, move to the next step; if
it's odd, you may want to handle it accordingly.
Output: Use a parallelogram to represent output. Label it "Print Even Value."
End: Finally, use an oval to indicate the end of the flowchart.

3.
import java.util.Scanner;

public class TriangleAreaCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
if (base > 0 && height > 0) {
double area = 0.5 * base * height;
System.out.println("Area: " + area);
} else {
System.out.println("The values cannot be negative or zero.");
}
}
}

4.
import java.util.Scanner;
public class SumAndAverage {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = scanner.nextInt();
double result = averageOfTheSumOfMultiples3And5(n);
System.out.println("Average: " + result);
}
public static double averageOfTheSumOfMultiples3And5(int n) {
int sum = 0;
int count = 0;
for (int i = 1; i <= n; i++) {
if (i % 3 == 0 || i % 5 == 0) {
sum += i;
count++;
}
}
if (count == 0) {
return 0.0;
}
return (double) sum / count;
}
}

You might also like