Kilograms Pounds 2.2 6.6 11.0 15.4 19.8 24.3 28.7 33.1 7 13 15 1) 1 kilogram is 2.20462 pounds (so, 2nd row will be 3 * 2.20462) 2) Use while statement to iterate 3) Set width to 12 for each columrn 4) Use printf) for precision up to tenths place
Q: In Java trace the table for the do while loop public class Main { public static void main(String[]…
A: According to the Question below the Solution:
Q: public static void main(String[] args) { int a = 3; int b = 2; int c = 4; What does the following…
A: Given code: class Main { //Define main function public static void main(String[] args) {…
Q: What is the output of the following program? public class printMystery public static void main…
A: Concept: A function is called by using the given syntax: function_name(arg1,arg2,..) here,…
Q: Can you change the code below to remove the repeated lines of code and use a loop to draw 4 sides of…
A: Below is the required code to avoid repetition:
Q: What will the following program display?public class ReviewQuestion5{public static void…
A: Here the function myMethod is using recursion. That is the function will call itself with one value…
Q: 3. Answer the following questions based on your understanding on loops. a) Suppose that a program…
A: Ans a: As a program executes the statements of a loop block at least once whenever the loop…
Q: What will be the output of the following C# code? public class sample { public static…
A: Question. What will be the output of the following C# code? public class sample {…
Q: What is wrong in the following code? public class Test { int x; public static void main(String[]…
A: Please find the answer below :
Q: Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each…
A: The following corrections need to be made to the program: In the while loop, logical and…
Q: Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and…
A: The objective of the Main.java program is to prompt the user to enter the value for n. Then call the…
Q: // Program displays some facts about a string public classDebugSeven3 { public static void…
A: Explanation: In Java the 1.The indexOf( ) method returns the position of the FIRST occurrence of…
Q: 15) With the following code, what is the result?: public class Loop ( public static void…
A: The above question is in Java and solved below:
Q: Problem: Write a Java program that displays all the leap years, 10 per line, from 1001 to 2100,…
A: Below is the required code in java language. Program Approach: Define a main class. Inside the…
Q: What is the result of executing the following code? public class Test { public static void main…
A: Answer to the above executable code of java with reason is detailed in step2.
Q: Do you know what is wrong with the program below? class Lab4Q2 { public static void main(String…
A: Here, first initialize "total" variable with zero(0) value because you have to add this value in…
Q: Write a for loop that prints: 1 2. countNum Ex: If the input is: 4 the output is: 1 2 3 4 1 import…
A: Here I have created the variables to store the values. Next, I have taken input from the user and…
Q: public static void main(String[] args) { System.out.println("Testing section one!"); int [] a = {1,…
A: The answer is given below.
Q: public static void doubleArray(int[] a){ int[] newA - new int[a.length]; for (int i = 0; i <…
A: Time complexity defines the worst case running time of the given program. It is denotes as O() -…
Q: 3. public static void main (String [] args) { int [] a = new int [15]; for (int i=0; i<a.length;…
A: Question is related to time complexity analysis .
Q: Use loops in java to write a program that reads items from the keyboard if a letter or number is…
A: Your java program is given below as you required with an output.
Q: 1. What is the output of the following code? public class Loopy {public static void main(String[]…
A: 1.Explanation for the given java code:In the class "Loopy", variable "x" is declared and initialized…
Q: class Output { public static void main(String args[]) { Integer i = new Integer(557); float x =…
A: Given, The programming language used = JAVA Code: class Output { public static void…
Q: public class Question1 { public static void main(String[] args) { double val; int counter = 0; int…
A: public class Question1 { public static void main (String[]args) { double val; int…
Q: Using a for Loop NewMultiply.java 1 // NewMultiply.java - This program prints the numbers ® through…
A: Here we are already given all the required variables to complete the code. Next, I have created a…
Q: public static void main(String [] args) { int num1 = 5, num2 = 10; swap(num1, num2);…
A: Given: public static void main(String [] args){ int num1 = 5, num2 = 10; swap(num1, num2);…
Q: Print person1's kids, call the incNumKids() method, and print again, outputting text as below. End…
A: Program code: File name: PersonInfo.java //import the required packages import java.util.*;…
Q: 15) With the following code, what is the result?: public class Loop ( public static void…
A: Below I have provided a java program for the given question. Also, I have attached a screenshot of…
Q: Rewrite the code using "while Loop" instead of "for Loop". Output must remain the same. CODE:…
A: Java code for above using while loop: import java.util.*; public class Prog { public static…
Q: public class output[ public static void main(String[] args) { int [][] D= new int [3][3]; int [] c =…
A: - We need to talk about the program and produce it's output.
Q: Write a program that takes in a line of text as input, and outputs that line of text in reverse. The…
A: required: Write a program that takes in a line of text as input, and outputs that line of text in…
Q: Rewrite the following program by using a for loop instead of the while loop.…
A: In for loop, you can have initialization, condition, updation in single line
Q: What will be the output of below given program: class Main public static void main(String[] args) {…
A: Task :- Write the output for given Java code.
Q: 1. Reading the following program and write the running results. public class Addition{ public static…
A: According to the question this program taking the length of all array and show it on the output…
Q: Create a flowchart for this Java program class Test { public static void main(String[] args) { for…
A: PROGRAM: //Defining class class Test { //Defining main() public static void main(String[] args) {…
Q: Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces.…
A: Actually, Java is a programming language originally developed by James Gosling at Sun Microsystems…
Q: Rewrite the code using "while Loop" instead of "for Loop". Output must remain the same.
A: import java.util.*;public class main { public static void main(String[] args) {int[] numbers = new…
Q: Write a program in Java that asks the user for a positive nonzero integer value. The program should…
A:
Q: There are two problems. One line of code needs changed and the way I'm running the code needs…
A: There are two lines in the code that needs to be changed: Change int result = addValues(args); to…
Q: In Java, int x = 27; int y = 2; do x = x / 3; while (x >= y); How many times would the loop…
A: The answer is 3. The above loop will execute Three times.
Q: Consider the following code, write a for enhanced loop to input the hours worked for each day…
A: Import the java utility package In Demo class enum is declared with the Days values Create a Object…
Q: 1. Write a Java program that will read numbers between 1 and 14 and will output the appropriate…
A: Here's the working code: import java.util.*;import java.lang.*;import java.io.*;public class…
Q: This is the question - Write an application that accepts any number of String values from a user…
A: import java.util.*;public class StringSort2 { public static void main(String[] args) { Scanner…
Q: Q 1: Write a complete Java program with your own code writing that contains: - A main method - A…
A: 1. public class Main { //class named Mainpublic static void main(String[] args) { //main class…
Q: in Java, Write a program that reads student scores, gets the best score, and then assigns grades…
A: Java program to determine the grade of a student corresponding to the score. Prompt user to enter…
Q: What is the output from the program below: public class testincr { public static void main(String…
A: GIVEN Question What is the output from the program below : public class testincr…
Q: 1-Write the pseudocode for this method 2-Flowchart for this method public static void…
A: 1:- pseudocode :- 1-bucketSort(arr[]) 2- initialize max_value = 0; 3- for every element in arr 4-…
Q: public class Test { } public static void main(String[] args) { int count } 1; while (count < 10) { }…
A: Answer:
Q: What will be the output of the following code? public class Test { final int x = 30; public static…
A: Step 1:- Explanation:- 1.Create a class whose name is Test2.Declare the variable x with the keyword…
1. What is the output of the following code?
public class Loopy {
public static void main(String[] args) {
int x = 1;
System.out.println("Before the loop");
while (x < 4) {
System.out.println("In the loop");
System.out.println("Value of x is " + x);
x = x + 1;
}
System.out.println("This is after the loop");
}
}
2. Write a
printf()and while statement. Do not use if while statement.
1) 1 kilogram is 2.20462 pounds (so, 2nd row will be 3 * 2.20462)
2) Use while statement to iterate
3) Set width to 12 for each column
4) Use printf() for precision up to tenths place
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images
- 19.16 LAB: Area of a triangle Using Heron's formula, you can calculate the area of a triangle if you know the lengths of all three sides. Given the length of each side of a triangle as input, calculate the area of the triangle using Heron's formula as follows: s = half of the triangle's perimeter area = the square root of s*(s-a)*(s-b)*(s-c), where a, b, and c are each sides of the triangle. Hint: Use the math function sqrt() for calculating the square root. Output the floating-point value of the area with two digits after the decimal point using the following statement once before all other cout statements:cout << fixed << setprecision(2); Ex: If the input for a, b, and c is: 3.0 4.0 5.0 the output is: Triangle area = 6.00 #include <iostream>#include <iomanip>#include <cmath>using namespace std; int main() { /* Type your code here. */ return 0;19.3 LAB: Hailstone sequence Given a positive integer n, the following rules will always create a sequence that ends with 1, called the hailstone sequence: If n is even, divide it by 2 If n is odd, multiply it by 3 and add 1 (i.e. 3n +1) Continue until n is 1 Write a program that reads an integer as input and prints the hailstone sequence starting with the integer entered. Format the output so that ten integers, each separated by a tab character (\t), are printed per line. The output format can be achieved as follows:print(n, end='\t') Ex: If the input is: 25 the output is: 25 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 Use Python, please.P3 – Inverted Pyramid of Odd Numbers Write a program that prompts the user to enter an integer from 1 to 15 (that shows the number of lines) and displays an inverted pyramid of odd numbers starting with 1, as shown in the following sample run: Please enter the number of lines: 7 13 11 9 7 5 3 1 3 5 7 9 11 13 11 9 7 5 3 1 3 5 7 9 11 9 7 5 3 1 3 5 7 9 7 5 3 1 3 5 7 5 3 1 3 5 3 1 3 1
- (PYTHON) A nutritionist who works for a fitness club helps members by evaluating their diets. As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consumed in a day. Then, she calculates the number of calories that result from the fat, using the following formula: calories from fat = fat grams x 3.9 Next, she calculates the number of calories that result from the carbohydrates, using the following formula: calories from carbs = carb grams x 4 The nutritionist asks you to write a program on *PYTHON* that will make these calculations.change normal body temperature to 36.5–37.5 °C #include<iostream>using namespace std;int main(){ float temp;cout<<"Enter the body temperature in Celsius\n";cin>>temp;if (temp>=37){cout<<"The quarantine of the patient is required\n";cout<<"Enter the name of the patient\n";string patient;cin>>patient;cout<<"Where the passenger is from\n";string place;cin>>place;cout<<patient<<" from "<<place<<"is to be quarantined at Hospital"; }cout<<"Normal temperature\n";}# NumberFun.py # using multiple functions. # copy/paste this program to run it first, you are supposed to use Google Chrome as Internet Browser for this course. # 1. calculate sum of the first n natural numbers, e.g.:1,2,3,... def sumN(n): sumN = 0 for i in range(1,n+1): sumN = sumN + i return sumN # 2. calculate sum of the square of the first m natural numbers, e.g.:1,4,9,... ### After you define/write/complete the function sumMSquare(m), remove the # sign as below to ENABLE next line of code ####def sumMSquare(m):### YOUR TURN TO DEFINE/WRITE/COMPLETE function sumMSquare(m) as below, based on sumN(n) # 3. call two functions defined previously within main() function def main(): print("This program computes the total and total of squares of the first") print("N/M natural numbers.\n") n,m = input("Please enter a value for N and M: ").split(",") print("The total of the first", n, "natural numbers is", sumN(int(n)))### After you define/write/complete the function sumMSquare(m), remove…
- 4.15 LAB: Hailstone sequence Given a positive integer n, the following rules will always create a sequence that ends with 1, called the hailstone sequence: If n is even, divide it by 2 If n is odd, multiply it by 3 and add 1 (i.e. 3n +1) Continue until n is 1 Write a program that reads an integer as input and prints the hailstone sequence starting with the integer entered. Format the output so that ten integers, each separated by a tab character (\t), are printed per line. The output format can be achieved as follows:print(n, end='\t') Ex: If the input is: 25 the output is: 25 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 My Code: n = int(input())print(n, end='\t')i = 1while n > 1: if not i % 10: print(n, end='\n') if n % 2 == 0: n = n//2 print(n, end='\t') else: n = 3*n+1 print(n, end='\t') i += 1print() Output: Screenshot attached!4.15 LAB: Hailstone sequence Given a positive integer n, the following rules will always create a sequence that ends with 1, called the hailstone sequence: If n is even, divide it by 2 If n is odd, multiply it by 3 and add 1 (i.e. 3n +1) Continue until n is 1 Write a program that reads an integer as input and prints the hailstone sequence starting with the integer entered. Format the output so that ten integers, each separated by a tab character (\t), are printed per line. The output format can be achieved as follows:print(n, end='\t') Ex: If the input is: 25 the output is: 25 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 117.54 PRACTICE: Functions***: Output guitar tabs C++ An earlier problem introduced guitar tabs. In this problem, the user can enter a sequence of chords, and the program should output the tabs in sequence. The first input is the number of chords to follow. If the input is 4 G C G D, the output should be: e|-3-0-3-2- B|-0-1-0-3- G|-0-0-0-2- D|-0-2-0-0- A|-2-3-2--- E|-3---3--- Hints: Use 6 C++ strings, one for each guitar string ("string" below will mean C++ string unless otherwise noted). Start by the e string with "e|-", the B string with "B|-", etc. For each user chord, append (using append()) to each string the appropriate item (a number or -) plus -, like "2-". When done, print the 6 strings one at a time separated by newlines.
- # NumberFun.py # using multiple functions. # copy/paste this program to run it first, you are supposed to use Google Chrome as Internet Browser for this course. # 1. calculate sum of the first n natural numbers, e.g.:1,2,3,... def totalN(n): totalN = 0 for i in range(1,n+1): totalN = totalN + i return totalN # 2. calculate sum of the cube of the first m natural numbers, e.g.:1,8,27,... ### After you define/write/complete the function totalMCube(m), remove the # sign as below to ENABLE next line of code ###def totalMCube(m):### YOUR TURN TO DEFINE/WRITE/COMPLETE function totalMCube(m) as below, based on totalN(n) # 3. call two functions defined previously within main() function def main(): print("This program computes the total and total of cubes of the first") print("N/M natural numbers.\n") n,m = input("Please enter a value for N and M: ").split(",") print("The total of the first", n, "natural numbers is", totalN(int(n)))### After you define/write/complete the function totalMCube(m),…Summary When you borrow money to buy a house, a car, or for some other purposes, then you typically repay it by making periodic payments. Suppose that the loan amount is L, r is the interest rate per year, m is the number of payments in a year, and the loan is for t years. Suppose that i = (r / m) and r is in decimal. Then the periodic payment is (first image which R=....): You can also calculate the unpaid loan balance after making certain payments. For example, the unpaid balance after making k payments is (second image which L'=....) : where R is the periodic payment. (Note that if the payments are monthly, then m = 12.) Instructions Write a program that prompts the user to input the values of L, r, m, t, and k. The program then outputs the appropriate values. Your program must contain at least two functions, with appropriate parameters, to calculate the periodic payments and the unpaid balance after certain payments. Make the program menu driven and use a loop so that the…7.12 LAB: Warm up: Parsing strings Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings.Ex: Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen Using string splitting, extract the two words from the input string and then remove any spaces. Output the two words.Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit.Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input string: Golden , Monkey First word: Golden Second word: Monkey Enter input…