Question

In: Computer Science

Instructions Complete the lab using “for loop”. Do not write the code in multiple programs. All...

Instructions

  • Complete the lab using “for loop”.
  • Do not write the code in multiple programs. All the 3 methods should be written in 1 program.
  1. Write a java program calls the following methods:
    1. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop.
    2. Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single line using for loop.
    3. hasAnEvenDigit: Takes an int (n) as parameter and returns whether n has at least one digit whose value is even. Return true if the number has at least one even digit else false if none of the digits are even. For example, the call hasAnEvenDigit(33267) should return true and hasAnEvenDigit(7591) should return false.

[Hint: n%10 returns the last digit and n/10 returns everything except the last digit]

Solutions

Expert Solution

Three methods for a , b and c written in java code in a single program as requested using "for loop". Please find the 3 methods code below as screenshot

Main() method Code calling the 3 methods below as screenshot

Result of first  method printing " n " stars as (*)

Result of second method printing first 10 multiples of given n param

Result of all third method  hasAnEvenDigit(33267) result as false as below

Result of all third method   hasAnEvenDigit(7591) result as false as below


Related Solutions

Complete the following in syntactically correct Python code. Write a program, using a for loop, that...
Complete the following in syntactically correct Python code. Write a program, using a for loop, that calculates the amount of money a person would earn over a period of time if his or her salary is 1 penny for the first day, 2 pennies for the second day, 4 pennies for the third day, and continues to double each day. 1.      The program should ask the user for the number of days the employee worked. 2.      Display a table showing the salary...
8.40 Lab 8e: BankBalance Introduction For this lab, you will use a do-while loop to complete...
8.40 Lab 8e: BankBalance Introduction For this lab, you will use a do-while loop to complete the task. A do-while loop has this basic structure: /* variable initializations */ do{ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } while (/*stop condition*/); Despite the structure of the do-while loop being different than that of a for loop and a while loop, the concept...
Write a complete program using the do-while loop that prompts the user to enter a string...
Write a complete program using the do-while loop that prompts the user to enter a string and displays its first and last characters. Repeat until the user enter a string that contains only one character. Here is an example to show you how the output may look like: <output> Enter a string ( type only one character to exit): this is my string The first character is t The last character is g Enter a string ( type only one...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var triangle.js Write a program that is required to use nested loops to generate a triangle as shown in the sample run below. The program should begin by prompting the user...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var Name: coinflip.js For this program you will have two functions, one called main and the second called flip. This program is also required the use of a loop construct. Write...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var Name: cookout.js Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8. Write a program called cookout.js, that calculates the number of...
Using the first code of this lab (Figure 1), write a code that displays the status...
Using the first code of this lab (Figure 1), write a code that displays the status of a push button on the LCD, that is, when you press it you should see “Pushed” on the LCD and when you release it, you should see “Released” #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2);...
Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code...
Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code of Conduct, providing the ET references for each of your responses. For questions with multiple parts, include multiple ET references as appropriate. What are the three broad categories of safeguards identified in Part 1 of the Code, in the Conceptual Framework for members in public practice? Which category of safeguard cannot be relied upon, by itself, to reduce threats to an acceptable level?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT