Write a program that will repeatedly ask the user to enter a floating-point numb
ID: 3797040 • Letter: W
Question
Write a program that will repeatedly ask the user to enter a floating-point number. the program should continue to ask the user to enter numbers until a zero or negative number is entered. At that point, the program should display the largest number entered. Example: the largest number entered was: 47.5 Write a program that will ask the user to enter an integer. the program should add all the integers from 1 to the entered number using a "while" loop, and display the sum. Show how the "while" loop in problem 3 can be re-written using a "for" loop instead. Write a program that includes a function called sqroot() that returns the squareroot of a positive integer. in the function, use a loop to find the squareroot . If the number does not have an integer squareroot , the function should return a value of zero. in the main() function, ask the user to enter a positive integer, then call the function and display the result. If a zero is returned, it should display "No integer squareroot ".Explanation / Answer
package chegg;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Question2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
List<Integer> numbers = new ArrayList<Integer>();
int num = 0;
System.out.println("Enter numbers");
while (scan.hasNextInt() && scan.nextInt()>0) {
num = scan.nextInt();
numbers.add(num);
}
System.out.println("largest number : " +Collections.max(numbers));
}
}
---------------------------------------------------------------------
package chegg;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = 1;
int num = 0;
int sum = 0;
System.out.print("Enter number ");
num = scan.nextInt();
while (i <= num) {
sum = sum + i;
++i;
}
System.out.print("Sum =" + sum);
}
}
--------------------------------------------------------------------
import java.util.Scanner;
public class Question4 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = 0;
int sum = 0;
System.out.print("Enter number ");
num = scan.nextInt();
for (int i = 1; i <= num; i++) {
sum = sum + i;
}
System.out.print("Sum =" + sum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.