Part A
Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised.
Part B
Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.
Will give thumbs up to best answer.
a)
import java.util.Scanner;
public class KeepReadingUntilValid {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
do {
n = in.nextInt();
} while (n < -13 || n > 13);
}
}
b)
import java.util.Scanner;
public class FactorialOfValid {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n;
do {
n = in.nextInt();
} while (n < 0 || n > 13);
int f = 1;
for(int i = 1; i <= n; ++i) {
f *= i;
}
System.out.println(f);
}
}
Part A Write a Java program that reads an integer n from the keyboard and loops...
Write a complete C program with a helper function that reads an integer from the keyboard and prints its factorial to the standard output
This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...
using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100. If n is out of range then print out an error message and ask for another input. This process repeats until a valid value for n is obtained. b) Inputs two 1D arrays of doubles A and B (of size n) from the keyboard. c) Inputs an integer k (from 1 to 3) from the keyboard. d) If k = 1 then it calculates...
In pseudocode Write a program which reads in one integer n as input, and then calculates n!, i.e., 1 × 2 × · · · × n, i.e., n-factorial. This is a count-controlled loop.
A java program Write a program that prompts for and reads in a positive integer into a variable n. Your program should then sum the first n ODD integers and display the sum. For example, if 3 is entered for n, your program should display the the sum 1 + 3 + 5. If 5 is entered, your program should display the sum 1 + 3 + 5 + 7 + 9. What is the...
1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java
In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...
Write a complete program thatdeclares an integer variable,reads a value from the keyboard into that variable, andwrites to standard output the square of the variable's value.
Write a program that reads a positive integer N, where N is greater than 1 and prints the value of the floating-point value SUM where SUM is the results of the following series. SUM = 1/1! + 2/2! + 3/3! + 4/4! + ... N/N! Note that your program should print the message “Sorry, bad N”” if N is <=1, and keep reading user input until the user enters a valid value for N. Also, note that all division operations...
JAVA. Write a program that reads in a series of positive integers and prints out the maximum value entered. The user will indicate they are finished entering numbers by entering zero or a negative integer.