1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GrogVix [38]
3 years ago
12

"Using the printf method, print the values of the integer variables bottles and cans so that the output looks like this: Bottles

: 8 Cans: 24 The numbers to the right should line up. (You may assume that the numbers have at most 8 digits.)"
Computers and Technology
1 answer:
Anika [276]3 years ago
6 0

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       

       System.out.println("Enter the number of bottles and cans:");

       int numberOfbottles = in.nextInt();

       int numberOfcans = in.nextInt();

       System.out.printf("Bottles: %8d\n", numberOfbottles);

       System.out.printf("Cans:    %8d\n", numberOfcans);

}

}

Explanation:

Ask user to input the number of bottles and cans using Scanner class

Print the results so that the numbers to the right line up (Since we know that the numbers have at most 8 digits, we can use %8d in printf. Also, be aware that how printf statements are written so that the numbers line up)

You might be interested in
Write biggerDigits.cpp that has a function called biggerDigits that uses two positive integer parameters with the same number of
fomenos

Answer:

Following are the program in the C++ Programming Language:

#include <iostream> //header file

using namespace std; //namespace

int biggerDigits(int n, int m) { //define function

if (n <= 0 || m <= 0) { //set if statement

return 0;  

}  

else { //set else statement

int a,b; //set integer variables

a = n % 10; //perform modulatio  

b = m % 10; //perform modulatio

int max = a; //set integer variable and assign value  

if (b > max) //set if statement

max = b; //initialize value to max

/*solution is here*/

return 10 * biggerDigits(n / 10, m / 10) + max;

}

}

int main() // main method  

{ // code is refer from question to make the program

cout << biggerDigits(567, 765) << endl; // call the function biggerdigits

cout << biggerDigits(123456, 444444) << endl; // call the function biggerdigits

//call function and print result

cout << biggerDigits(999, 111) << endl; // call the function biggerdigits

return 0; // return the integer 0

}

Explanation:

Here, we set the header file "<iostream>" and namespace "std" then, we set a function "biggerDigits()" and pass two integer type arguments inside it.

  • we set if condition in which when the variable "n" is less than equal to 0 or m is less than equal to 0 then, it return 0.
  • we set the else statement inside it we set two integer type variables "a" and "b" then, perform modulation with both the variables.
  • we set integer variable "max" and assign value of a in it.
  • we set if condition in which we check when the variable b is greater than variable max then, initialize the value of variable b in the variable max and return the solution through recursion.
7 0
3 years ago
What position should you hand be on the steering wheel? yuyuyhj
Diano4ka-milaya [45]

Answer:

9 and 3

Explanation:

its the right way and njcs wdhiqgua wdiu posef

8 0
3 years ago
Write a program that will read in aweight in kilograms and grams and will output the equivalent weightin pounds and ounces. Use
ozzi

<u>C++ program for converting kilograms and grams to pounds and ounces</u>

#include <iostream>

using namespace std;

void computation(double kilog, double gram, double& pon, double& oun) /*defining function for computing*/

{

pon = kilog*2.2046;/*Formula for converting*/

oun= gram*0.03527;

}

void output(double pon,double oun)/*For printing output*/

{

   cout << "Pounds are: " << pon << endl;

   cout << "Ounce are: " << oun << endl;

}

void input(double &kilog,double&gram)/*for taking output*/

{

   cout << "Enter kilograms to convert: ";

   cin >> kilog;

  cout << "Enter grams to convert: ";

   cin >> gram;

}

int main() //driver function

{

double kilog = 0.0,gram = 0.0,oun=0.0,pon=0.0;//Initializing

int choice = 0;

while (1) {  

cout << "Enter- 1 for converting kilogram and grams to pounds and ounces" << endl;

cout << "Enter-2 for exiting" << endl;

cout << "Please Enter choice: ";/*Asking choice from user*/

cin >> choice;

if (choice == 1) {

input(kilog,gram);/*Calling function for taking input*/

computation(kilog, gram, pon, oun); /*calling function for computing*/

output(pon,oun);/*calling function for output*/

}

else {

return 0;

}

}

}

<u>Output</u>

Enter- 1 for converting kilogram and grams to pounds and ounces

Enter-2 for exiting

Please Enter choice:1

Enter kilograms to convert:20

Enter grams to convert:10

Pounds are: 44.092

Ounce are: 0.3527

Enter- 1 for converting kilogram and grams to pounds and ounces

Enter-2 for exiting

Please Enter choice: 2

6 0
4 years ago
Which of the following is not a valid technique to create a function stub?
In-s [12.5K]

An option which isn't a valid technique to create a function stub is to: D. leave the function body empty.

<h3>What is a function stub?</h3>

A function stub can be defined as a type of function that can be called safely without an error. However, a function stub has no definition because it doesn't actually perform any action when called.

In this context, leaving the function body empty is an option which isn't a valid technique to create a function stub.

Read more on function stub here: brainly.com/question/17214711

#SPJ1

6 0
3 years ago
Do you believe that OOP should be phased out and we should start working on some alternative
masya89 [10]

Answer:  No, working on alternative instead of OOP is not the best option. In this time of computer technology, there are many different ways to solve a problem. OOP is the choice of law when it comes to solve a problem using object oriented solutions. OOP is a way of developing software that sums up the responsibilities of the system in a company which works together on objects. Objects are not the differentiating characteristics of Object Oriented Programming, instead these are necessary for writing object oriented software.

Why we shouldn't use the other alternatives. Here are two statements which supports my opinion:

  • If a problem is classified or divided in many different categories, this will results in complex interactions, for which an object oriented modeling will be selected. The problems like these ends up in complex results in other models.
  • The standardized approach towards solving problems is Object Oriented designs patterns. By using OO, solutions are generated, which are understandable for both creator and the coder. There are different numbers of design patterns of OO.

8 0
4 years ago
Other questions:
  • Rather than manually setting a print area each time you want to print a range, you can ____ the range.
    13·1 answer
  • Explaing why the findings are different between a general purpose search engine ( google) and a meta search engine ( ask jeeves)
    9·1 answer
  • How are procedural and object-oriented programming approaches similar?
    9·1 answer
  • What are the first two models, e.g. diagrams that affect the entire system, that are built during the CoreProcess to discover an
    5·1 answer
  • I will mark brainillist if someone answers Donethkm question its How can a Word user insert a page break into a document to isol
    11·2 answers
  • Which formal security-related process should take place at the beginning of the code creation project? Group of answer choices R
    13·1 answer
  • A computer can function in the absence of software true or false​
    15·2 answers
  • A RAID structure ____. is primarily used for security reasons is primarily used to ensure higher data reliability stands for red
    14·1 answer
  • Although the chi-square distribution is continuous, it is used to analyze discrete (counts) data
    6·1 answer
  • a document contains a list of items that appear in no particular order. what is the best way to format the list
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!