217k views
5 votes
A drink costs 2 dollars. A taco costs 3 dollars. Given the number of each, compute total cost and assign totalCost with the result in java program

User Fightlight
by
8.0k points

1 Answer

3 votes

Here's a Java program that takes the number of drinks and tacos as input and calculates the total cost:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of drinks: ");

int numDrinks = scanner.nextInt();

System.out.print("Enter the number of tacos: ");

int numTacos = scanner.nextInt();

double drinkCost = 2;

double tacoCost = 3;

double totalCost = (numDrinks * drinkCost) + (numTacos * tacoCost);

System.out.println("Total cost: $" + totalCost);

}

}

User Brandon Essler
by
7.0k points