Introduction to Java Problem 1: Write a program with a loop that lets the user e
ID: 3680704 • Letter: I
Question
Introduction to Java
Problem 1:
Write a program with a loop that lets the user enter a series of populations. The user should enter -99 to indicate the end of the series. After all the numbers have been entered, the program should display the smallest population entered.
Problem 2:
Write Java statements (not a whole program) to accomplish the following. When the value of partTimeis less than fullTime decrement the value of fullTime by 1 using the decrement operator, otherwise increment the value of fullTime by 1 using the increment operator.
Then in either case, display the new value of fullTime labled with "Fulltime value: ".
Explanation / Answer
//Problem 1
//The program exits,if the use enters the number -99
//Smallest_Population.java
import java.util.Scanner;
public class Smallest_Population
{
public static void main(String[] args)
{
int n, small;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the series:");
n = s.nextInt();
if(n==-99)
{
System.exit(0);
}
else
{
int a[] = new int[n];
System.out.println("Enter the population:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
small = a[0];
for(int i = 0; i < n; i++)
{
if(small > a[i])
{
small = a[i];
}
}
System.out.println("Smallest Population entered is :"+small);
}
}
}
/*
Sample out put
D:/Cheggqa/java Smallest_Population
Enter number of elements in the series:3
Enter the population:
22
11
66
Smallest Population entered is :11
D:Cheggqa/java Smallest_Population
Enter number of elements in the series:-99
D:Cheggqa
*/
Problem 2:
int partTime,fullTime;
//take values of partTime and fullTime
if(partTime<fullTime)
{
fullTime--;
}
else
{
fullTime++;
}
System.out.println("Fulltime Value"+fullTime);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.