Question
What is the output from the following code segments: String name; int position = 0; Scanner input = new Scanner(System.in); System.out.print(Enter name: ); name =
What is the output from the following code segments:
String name;
int position = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter name: ");
name = input.nextLine();
while(position < name.length()) {
System.out.println(name.charAt(position));
position++;
for (int r = 0; r < 6; r++)
{
System.out.print("#");
for (int c = 0; c < r; c++)
{
System.out.print(" ");
}
System.out.println("#");
}
for (int r = 7; r > 0; r--)
{
for (int c = 0; c < r; c++)
{
System.out.print("*");
}
System.out.println();
}
for (int r = 0; r < 6; r++)
{
for (int c = 0; c < r; c++)
{
System.out.print(" ");
}
System.out.println("__");
}
Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies.
Input Validation: Do not accept a number less than 1 for the number of days worked
Write a program that generates a random number (0 - 50) and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." if the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.
Update the program in questions #4 to keep a count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should display the number of guesses. Now add another loop to ask the user if he or she wishes to play the guessing game again. If so, the loop should repeat, otherwise it should terminate.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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