package brainly;
import java.util.*;
/**
*
* @author CotrinaAlejandra
*/
public class Brainly {
/*Provide the java code, including a comment with your name, course code and date.
Name:
Course:
Date: */
public static void main(String[] args) {
// TODO code application logic here
int number;
Scanner sc = new Scanner(System.in);
System.out.print("Write a four digit number: ");
number=sc.nextInt();
String newLine= String.valueOf(number);
System.out.println(newLine.charAt(0)+" "+newLine.charAt(1)+" "+newLine.charAt(2)+" "+newLine.charAt(3));
}
}
Index
File
Catalog
The two ways to use the help menu is by searching of the contents or searching the index.
Answer:
a. cout<<hidden(15,10)<<endl;
output = 5
b. cout << compute(3, 9) << endl;
output=3
c. cout << hidden(30, 20) << " " << compute(10, hidden(30, 20)) << endl;
output = 10
d. x = 2; y = 8; cout << compute(y, x) << endl;
output= 8
Explanation:
solution a:
num1= 15;
num2= 10;
according to condition 1, num1 is not greater than 20. In condition 2, num2 is also not greater than 20.
so,
the solution is
return num1 - num2 = 15 - 10 = 5
So the output for the above function is 5.
solution b:
as in function there are two integer type variables named as one and two. values of variables in given part are:
one = 3
two = 9
secret = one = 3
for (int i= one + 1 = 3+1 = 4; i<=9%2=1; i++ )
9%2 mean find the remainder for 9 dividing by 2 that is 1.
// there 4 is not less than equal to 1 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 3;
so answer return from the function is 3.
solution c:
As variables in first function are num1 and num2. the values given in part c are:
num1 = 30;
num2= 20;
According to first condition num1=30>20, So,
num1= num2/10
so the solution is
num1 = 20/10 = 2
now
num1=2
now the value return from function Hidden is,
return num1*num2 = 2* 20 = 40
Now use the value return from function hidden in function compute as
compute(10, hidden(30, 20))
as the value return from hidden(30, 20) = 40
so, compute function becomes
compute(10, 40)
Now variable in compute function are named as one and two, so the values are
one= 10;
two = 40;
as
secret = one
so
secret = 10;
for (int i= one + 1 = 10+1 = 11; i<=40%2=0; i++ )
40%2 mean find the remainder for 40 dividing by 2 that is 0.
// there 11 is not less than equal to 0 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 10;
so answer return from the function is 10.
solution d:
Now variable in compute function are named as one and two, so the values are
one = y = 8
two = x = 2
There
Secret = one = 8;
So
for (int i= one + 1 = 8+1 = 9; i<=2%2=0; i++ )
2%2 mean find the remainder for 2 dividing by 2 that is 0.
// there 9 is not less than equal to 0 so loop condition will be false and loop will terminate. statement in loop will not be executed.
So the answer will be return from function compute is
return secret ;
secret = 8;
so answer return from the function is 8.
Answer:
a = int(input("Enter first value between 1 - 10"))
b = int(input("Enter second value between 1 - 10"))
z = a + b
z += 30
print("The value of z = ", z)
Explanation:
The code is written above in python language to perform the given task.
Now, let us explain each statement of code.
Step 1: The first two lines take input from the user prompting the user to enter the values between 1 to 10.
Then the values are type casted to int using int().
The values are stored in variables a and b.
Step 2: Then, the values of a and b are added to get another variable z.
Step 3: The statement 'z += 30' is equivalent to z = z+30
It adds 30 to the variable z and stores it in the same variable z.
Step 4: Finally the value of variable 'z' is printed using print() command.
(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base. (1 pt)
(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head. (2 pts)
(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt)
while (arrowHeadWidth <= arrowBaseWidth) {
// Prompt user for a valid arrow head value
}
Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:
Enter arrow base height:
5
Enter arrow base width:
2
Enter arrow head width:
4
**
**
**
**
**
****
***
**
*
This is what I have:
import java.util.Scanner;
public class DrawHalfArrow
{
public static void main(String[] args)
{
Scanner scnr = new Scanner(System.in);
int arrowBaseHeight = 0;
int arrowBaseWidth = 0;
int arrowHeadWidth = 0;
System.out.println("Enter arrow base height:");
arrowBaseHeight = scnr.nextInt();
System.out.println("Enter arrow base width:");
arrowBaseWidth = scnr.nextInt();
while (arrowHeadWidth >= arrowBaseWidth)
{
System.out.println("Enter arrow head width:");
arrowHeadWidth = scnr.nextInt();
}
// Draw arrow base (height = 3, width = 2)
for(int i=0; i < arrowBaseHeight; ++i)
{
for(int j=0; j < arrowBaseWidth; ++j)
{
System.out.print("*");
}
System.out.println();
}
// Draw arrow head (width = 4)
for(int i=0; i < arrowHeadWidth; ++i)
{
for(int j=0; j < arrowHeadWidth-i; ++j)
{
System.out.print("*");
}
System.out.println();
}
return;
}
}
Answer:
The modified program in Java is as follows:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int arrowHeadWidth, arrowBaseWidth, arrowBaseHeight;
System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();
System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();
System.out.print("Base Height: "); arrowBaseHeight = input.nextInt();
while (arrowHeadWidth <= arrowBaseWidth) {
System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();
System.out.print("Base Width: "); arrowBaseWidth = input.nextInt(); }
for(int i = 0; i<arrowBaseHeight; i++){
for(int j = 0; j<arrowBaseWidth;j++){
System.out.print("*"); }
System.out.println(); }
for(int i = arrowHeadWidth; i>0;i--){
for(int j = 0; j<i;j++){
System.out.print("*"); }
System.out.println(); }
}
}
Explanation:
This declares the arrow dimensions
int arrowHeadWidth, arrowBaseWidth, arrowBaseHeight;
This get input for the head width
System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();
This get input for the base width
System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();
This get input for the base height
System.out.print("Base Height: "); arrowBaseHeight = input.nextInt();
This loop is repeated until the head width is greater than the base width
while (arrowHeadWidth <= arrowBaseWidth) {
System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();
System.out.print("Base Width: "); arrowBaseWidth = input.nextInt(); }
This iterates through the base height
for(int i = 0; i<arrowBaseHeight; i++){
This iterates through the base width
for(int j = 0; j<arrowBaseWidth;j++){
This fills the base
System.out.print("*"); }
This prints a new line
System.out.println(); }
These iterate through the arrow head
for(int i = arrowHeadWidth; i>0;i--){
for(int j = 0; j<i;j++){
This fills the arrow head
System.out.print("*"); }
This prints a new line
System.out.println(); }
Answer:
Typefaces is the correct answer to this question.
Explanation:
Answer:
The height of the ball after t seconds is h + vt - 16t 2 feet:
def main():
getInput()
def getInput():
h = int(input("Enter the initial height of the ball: ")) # Adding the int keyword before input() function
v = int(input("Enter the initial velocity of the ball: ")) # Same as above
isValid(h,v)
def isValid(h,v):
if ((h <= 0) or (v <= 0)):
print("Please enter positive values")
getInput()
else:
maxHeight(h,v)
def maxHeight(h,v):
t = (v/32)
maxH = (h + (v*h) - (16*t*t))
print ("\nMax Height of the Ball is: " + str(maxH) + " feet")
ballTime(h, v)
def ballTime(h,v):
t = 0
ballHeight = (h + (v*t) - (16*t*t))
while (ballHeight >= 0):
t += 0.1
ballHeight = (h + (v*t) - (16*t*t))
print ("\nThe ball will hit the ground approximately after " + str(t) + " seconds")
# Driver Code
main()
Answer:
I am writing a python code.
def getInput():
h = int(input("enter the height: "))
v = int(input("enter the velocity: "))
isValid(h,v)
def isValid(h,v):
if (h<= 0 or v<=0):
print("not positive ")
else:
height = maximumHeight(h,v)
print("maximum height of the ball is", height," ft.")
balltime = ground_time(h,v)
print("The ball will hit the ground after", balltime, "s approximately.")
def maximumHeight(h,v):
t = (v/32)
maxheight = (h + (v*t) - (16*t*t))
return maxheight
def ground_time(h,v):
t = 0.1
while(True):
heightofball = (h + (v*t) - (16*t*t))
if (heightofball <= 0):
break
else:
t += 0.1
return t
Explanation:
There are four functions in this program.
getInput() function is used to take input from the user which is height and velocity. h holds the value of height and v holds the value of velocity. input() function is used to accept values from the user.
isValid() function is called after the user enters the value of height and velocity. This function first checks if the value of height and velocity is less than 0. If it is true the message not positive is displayed. If its false then maximumHeight() is called which returns the maximum height of the ball and function ground_time() is called to return the time when the ball will hit the ground.
maximumHeight() function first divides the value of velocity with 32 as the ball will reach its maximum height after v/32 seconds. It then returns the maximum height by using the formula: heightofball = (h + (v*t) - (16*t*t)).
ground_time() calculates the time the ball takes to reach the ground. There is a while loop to height after every 0.1 second and determine when the height is no longer a positive. It uses (h + (v*t) - (16*t*t)) formula to calculate the height and when the value of height gets less than or equal to 0 the loop terminates otherwise it keeps calculating the height while adding 1 to the value of t at each iteration. After the loop breaks, it returns the value of t.
To see the output of the maximum height and time taken by ball to reach the ground, you can call the getInput() function at the end of the above program as:
getInput()
Output:
enter the height: 9
enter the velocity: 10
maximum height of the ball is 10.6525 ft.
the ball will hit the ground after 1.2 s approximately.