Question
LAB3 #1 : Suppose you have a real number variable x. Write a Java expression that computes the following value y while using the *
LAB3
#1: Suppose you have a real number variable x. Write a Java expression that computes the following value y while using the * operator less than equal to four times to compute x4, x3, and x2. (Hint: please consider using variables.) The uses of * operator for coefficient multiplication are not counted. (2pt) (You don't need to use a loop structure for this question.)
y = 12.3x4 - 9.1x3 + 19.3x2 - 4.6x + 34.2
Write a complete program for the above program task.
The use of * operator for numeric multiplication is expected.
To write a program, you may consider using variables, initialized by any number, for example 5 or 10 for variable x. The program is supposed to print out the correspondent y value (result) typed double.
#2: Complete the following code, replacing the "FINISH ME" parts with your own code to generate the following output: (2pt)
public class Count2 {
public static void main(String[] args) {
for (int i = /* FINISH ME */ ) {
System.out.println( /* FINISH ME */ );
}
}
}
Expected output:
2 times 1 = 2
2 times 2 = 4
2 times 3 = 6
2 times 4 = 8
#3: What is the output of the following sequence of loops? (2pt)
for (int i = 1; i <= 2; i++) {
for ( int j = 1; j <= 3; j++) {
for ( int k = 1; k <= 4; k++) {
System.out.print("*");
}
}
System.out.print("!");
System.out.println();
}
#4: Write a program to draw the following ASCII art. Please consider develop a table that determines the expressions for the number of each type of character on each of the 6 lines in the following output. You need to apply the expressions to the nested loops. (2pt)
!!!!!!!!!!!!!!!!!!!!!!
\\!!!!!!!!!!!!!!!!!!//
\\\\!!!!!!!!!!!!!!////
\\\\\\!!!!!!!!!!//////
\\\\\\\\!!!!!!////////
\\\\\\\\\\!!//////////
#5: Write a program which contains nested for loops to produce the following output: (2pt)
1 // 4-space
2 // 3-space
3 // 2-space
4 // 1-space
5 // no space * Note that the attached comments are optional.
* Extra Work ( 2-credit). Complete Mirror class that was given in class material (Chapter 2) with additional methods. The following shows the structure of the class, Mirror Remark: You are expected to declare constant variable and use the constant within the methods.
public class Mirror {
public static final int SIZE = 4;
public static void main(String[] args) {
line();
topHalf();
bottomHalf();
line();
}
public static void topHalf() {
for (int line = 1; line <= 4; line++) {
// contents of each line
}
}
public static void bottomHalf() {
for (int line = 1; line <= 4; line++) {
// contents of each line
}
}
public static void line() {
// ...
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started