What's new

Need help pano to i code?

chiper

Established
Joined
May 1, 2018
Posts
134
Reaction
5
Age
22
Create a java program that uses classes (instance variables, methods, and constructors) and objects to do the following:


accepts three numbers
computes the SUM of all three numbers and determines whether the SUM is odd or even
determine which is the highest and lowest number
Sort the three numbers in ascending order.
Sort the three numbers in descending order.
 

zhero25

Grasshopper
i'll just give you an idea about the program... pero ikaw na bahala sa iba

import java.util.Scanner;

public class ArithmeticSmallestAndLargest {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter first integer: ");
int number1 = input.nextInt();

System.out.print("Enter second integer: ");
int number2 = input.nextInt();

System.out.print("Enter third integer: ");
int number3 = input.nextInt();
input.close();

int sum = number1 + number2 + number3;
int average = sum / 3;
int product = number1 * number2 * number3;

int largest = number1;
if (number2 > largest)
largest = number2;
if (number3 > largest)
largest = number3;

int smallest = number1;
if (number2 < smallest)
smallest = number2;
if (number3 < smallest)
smallest = number3;

System.out.printf("Sum is %d%n", sum);
System.out.printf("Average is %d%n", average);
System.out.printf("Product is %d%n", product);
System.out.printf("Largest is %d%n", largest);
System.out.printf("Smallest is %d%n", smallest);
}
}
 
Top