1_Declare an int variable called aNumber and assign it a value of 24? 2_Declare
ID: 2246666 • Letter: 1
Question
1_Declare an int variable called aNumber and assign it a value of 24?
2_Declare 2 double variables, myMoney and yourMoney on the same line. Do NOT give them initial values?
3_Output to the screen the result of the math problem 23 - 87 X 45. Have the program calculate the result?
4_Output (without quotes) "The square root of 87 is:xx", where xx is the actual square root of 87. Have the program calculate the square root value?
5_Get a char from the user. If the value of the char is 'U', output, "It's You.", if the value is 'I', output, "I did it.", otherwise, output, "I don't know who did it." Assume the user will enter a valid single character.?
6_Output the following, showing the quotes as shown below:
MLK said, "the measure of a man is where he stands in times of adversity."
7_Output the ASCII value of the minus sign (-). You must do this without consulting the ASCII table.
Output the char value that corresponds to the ASCII value 93, again without using the ASCII table.
8_Declare a double array of 4 elements.
9_Given the declaration below, create a loop that will efficiently output every value in the savings array. Assume you know the size of the array is 35 elements.
In another loop, only output values from the savings array that are more than 8.1.
double savings[35] = {6.06, 3.03, 5.31,3.32, 5.49, 5.24,9.3,3.81,5.02,8.52,9.64,4.73,4.61,2.09,5.23,5.91,9.21,9.14,7.32,9.84,9.84,7.47,1.69,5.36,3.07,4.99,2.45,5.7,6.61,9.43,6.74,4.27,2.79,9.66,1.73};
10_Which of the following lines, if any, will cause a syntax error? What is the error? If you believe a particular line will create output, state the output. Try to answer this without typing in the code.
bool b = 5 == 6;
int _o=0,_=35,_t_;
double doubler, doubled, doubles=2,Int;
char ZERO = 0,, two='t';
cout << "16 + 3" << 16 + 3;
cout << "H" << 'ello there 1';
cout << "H" << "ello there" << '2';
cout << 'H' << "ello there" << 3;
Explanation / Answer
Hi,
Since you have not specified in which language you need to solution, so I am answering it in Java-
Ans 1 -
int aNumber = 24;
Ans 2 -
double myMoney, yourMoney ;
Ans 3 -
int val;
val=(23-(87*45))
System.out.println(val);
Ans 4 -
public class Test{
public static void main(String args[]) {
System.out.printf("The square root of 87 is:%f", Math.sqrt(87));
}
}
Ans 5 -
import java.util.Scanner;
public class HelloWorld{
public static void main(String args[]) {
char val;
Scanner s=new Scanner(System.in);
System.out.printf("Enter the char value");
val=s.next().charAt(0);
if(val=='U'){
System.out.println("It's You.") ;
}
else if(val=='I'){
System.out.println("I did it") ;
}
else
System.out.println("I don't know who did it");
}
}
Ans 6-
public class HelloWorld{
public static void main(String args[]) {
System.out.println("MLK said, "the measure of a man is where he stands in times of adversity."");
}
}
Ans 7 -
import java.util.Scanner;
public class HelloWorld{
public static void main(String args[])
{
char character = '-';
int ascii = (int) character;
System.out.println(ascii);
int ascii1 = 93;
char character1 = (char) ascii1;
System.out.println(character1);
}
}
Ans 8 -
double arr[]=new double[4];
Ans 9-
import java.util.Arrays;
public class HelloWorld{
public static void main(String args[]) {
double savings[] = {6.06, 3.03, 5.31,3.32, 5.49, 5.24,9.3,3.81,5.02,8.52,9.64,4.73,4.61,2.09,5.23,5.91,9.21,9.14,7.32,9.84,9.84,7.47,1.69,5.36,3.07,4.99,2.45,5.7,6.61,9.43,6.74,4.27,2.79,9.66,1.73};
System.out.println(Arrays.toString(savings));
}
}
Ans 10-
bool b = 5 == 6; // Syntax Error
int _o=0,_=35,_t_;
double doubler, doubled, doubles=2,Int;
char ZERO = 0,, two='t';
cout << "16 + 3" << 16 + 3;
cout << "H" << 'ello there 1'; //Syntax Error
cout << "H" << "ello there" << '2';
cout << 'H' << "ello there" << 3;
Regards,
Vinay Singh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.