0% found this document useful (0 votes)
8 views2 pages

Java Programs With Output

The document contains two Java programs: the first calculates the sum of the highest and lowest numbers from user input, while the second generates a specific number series based on user input. Both programs include input validation and provide corresponding outputs based on the inputs provided. Example outputs are given for different inputs to illustrate the functionality of each program.

Uploaded by

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

Java Programs With Output

The document contains two Java programs: the first calculates the sum of the highest and lowest numbers from user input, while the second generates a specific number series based on user input. Both programs include input validation and provide corresponding outputs based on the inputs provided. Example outputs are given for different inputs to illustrate the functionality of each program.

Uploaded by

Mohit Gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programs with Output

Problem 1: Sum of Highest & Lowest Numbers

import [Link].*;

public class Problem1 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter number of inputs: ");
int n = [Link]();
if (n < 3) {
[Link]("Invalid Input");
return;
}
int[] arr = new int[n];
[Link]("Enter the numbers:");
for (int i = 0; i < n; i++) {
arr[i] = [Link]();
}
int max = arr[0], min = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
}
[Link]("Sum of highest and lowest numbers: " + (max + min));
}
}
Output:
Enter number of inputs: 5
Enter the numbers:
10 20 5 8 15
Sum of highest and lowest numbers: 25

Problem 2: Number Series Generation

import [Link].*;

public class Problem2 {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
if (n <= 0) {
[Link]("Wrong input");
return;
}
for (int i = 1; i <= n; i++) {
[Link]((i * (i + 1)) + " ");
}
}
}
Java Programs with Output

Output:
Input: 5
2 6 12 20 30

Input: 7
2 6 12 20 30 42 56

Input: -5
Wrong input

You might also like