a) Write a Java test program, all the code should be in a single main method, th
ID: 3550523 • Letter: A
Question
a) Write a Java test program, all the code should be in a single main method, that calculates and outputs the average of the numbers 1, 2, 9, 27, and 54. Your program should store the average in a variable and print the content of that variable.
b) Write a Java test program (all the code should be in a single main method) that reads a word representing a domain name from the user. Your program should concatenate www. to the front of the word, and .com to the back of the word, and print the result of the concatenation.
This is an optimal place to use the JOptionPane.showInputDialog method for input. Recall that this method returns a String.
*This exercise requires JGrasp software.
Explanation / Answer
1.
public class AverageCalculator {
public static void main(String[] args) {
double average;
double sumOfNumbers = 1+2+9+27+54;
int noOfItems = 5;
average = sumOfNumbers/noOfItems;
System.out.println("The average is: "+average);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.