Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a little help with a programming assignment, and any help would be apprec

ID: 3874755 • Letter: I

Question

I need a little help with a programming assignment, and any help would be appreciated. We are tasked with doing the following:

Create a program that:

1.) Takes in integers from an user until they enter 0. At that point, the following calculations will be output.

2.) Your program must output the smallest integer the user entered. Negative numbers are considered.

3.) Your program must output the largest integer the user entered THAT IS DIVISIBLE BY 2.

4.) Your program must output the count of even integers within the sequence.

5.) Your program must output the sum of the positive integers only.

Sample Outputs:

1.)

2.)

3.)

4.)

Again, any help on this would be greatly appreciated. Thank you!

Explanation / Answer

Program is written in java:

Tips: while compiling in your machine keep the clas name as Chegg.java

package com.javatpoint;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Chegg {

public static void main(String[] args) {

// TODO Auto-generated method stub

int temp=0,min=0,max=0,index=-1,sum=0;

System.out.println("Enter the no:");

Scanner sc=new Scanner(System.in);

List<Integer> l=new ArrayList<Integer>();

while((temp=sc.nextInt())!=0)

{

l.add(temp);

System.out.println("Enter the no:");

}

min=l.get(0);

max=l.get(0);

for(int i=0;i<l.size();i++)

{

if(min>l.get(i))

min=l.get(i);

if(l.get(i)>0){

sum=sum+l.get(i);

}

}

max=min;

for(int i=0;i<l.size();i++){

if(max<=l.get(i) && l.get(i)%2==0){

max=l.get(i);

index=i+1;

}

}

System.out.println("The minimum integer is :"+min);

System.out.println("The largest integer divisible by 2 is :"+max);

System.out.println("The count of the even integer in the sequence :"+index);

System.out.println("The sum of positive no :"+ sum);

System.out.println(l);

}

}

Output:

Enter the no:
1
Enter the no:
8
Enter the no:
4
Enter the no:
-2
Enter the no:
-5
Enter the no:
0
The minimum integer is :-5
The largest integer divisible by 2 is :8
The count of the even integer in the sequence :2
The sum of positive no :13
[1, 8, 4, -2, -5]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote