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