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

CSC Homework #2

This document contains a Java program that takes three integer inputs from the user and finds the largest, smallest, and sum of the largest and smallest numbers. It initializes variables to store the three user inputs and the largest, smallest, and sum values. It then compares the numbers to find the largest and smallest values. Finally, it prints out the largest number, smallest number, and sum of the largest and smallest numbers.

Uploaded by

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

CSC Homework #2

This document contains a Java program that takes three integer inputs from the user and finds the largest, smallest, and sum of the largest and smallest numbers. It initializes variables to store the three user inputs and the largest, smallest, and sum values. It then compares the numbers to find the largest and smallest values. Finally, it prints out the largest number, smallest number, and sum of the largest and smallest numbers.

Uploaded by

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

CSC 109- Spring 2023

College of New Caledonia

Homework # 02
Name - Manpreet Singh
Student ID -0164720
Submission Date - 16-02-2023

MAIN CODE-
import java.util.Scanner;
public class Main
{
// main method begins execution of Java application
public static void main(String[] args)
{
// create Scanner to obtain input
Scanner input = new Scanner(System.in);

// initialize variables
int num1; // first integer for user input
int num2; // second integer for user input
int num3; // third integer for user input
int largest; // largest number from num1, num2, and num3
int smallest; // smallest number from num1, num2, and num3
int sum; // sum of largest and smallest
System.out.print("Enter first integer: ");
num1 = input.nextInt(); // read first integer from user

System.out.print("Enter second integer: ");


num2 = input.nextInt(); // read second integer from user
CSC 109- Spring 2023
College of New Caledonia

System.out.print("Enter third integer: ");


num3 = input.nextInt(); // read third integer from use

// Compare the numbers to find the smallest value


smallest = num1;
if (num2 <= smallest)
smallest = num2;

if (num3 <= smallest)


smallest = num3;

// Compare the numbers to find the largest value


largest = num1;
if (num2 >= largest)
largest = num2;

if (num3 >= largest)


largest = num3;
sum = smallest + largest ; // add numbers
System.out.printf("Largest number is :%d\n", largest); // display the largest
number
System.out.printf("Smallest number is: %d\n", smallest);// display the smallest
number
System.out.printf("Sum of smallest and largest numbers is: %d\n", sum);//
display the sum
} // end method main

} // end class main


CSC 109- Spring 2023
College of New Caledonia

Output-
Enter first integer: 1
Enter second integer: 2
Enter third integer: 3
Largest number is :3
Smallest number is: 1
Sum of smallest and largest numbers is: 4

You might also like