Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class CheapPizza {
- public static void main (String[] args) throws FileNotFoundException {
- Scanner read = new Scanner(new File("C:\\Users\\1307320\\Desktop\\pizzas.txt"));
- int x = 1;
- double cost = 0;
- double maxcost = 99;
- String maxtopping = "";
- String topping = "";
- int size = 0;
- int maxsize = 0;
- search:
- while (read.hasNext()) {
- if (x == 1) {
- topping = read.next();
- x = x + 1;
- }
- else if (x == 2) {
- size = read.nextInt();
- x = x + 1;
- }
- else if (x == 3) {
- cost = read.nextDouble();
- x = 1;
- if (cost < maxcost) {
- maxcost = cost;
- maxtopping = topping;
- maxsize = size;
- }
- }
- }
- System.out.println("The cheapest pizza: The " + maxsize + " inch " + maxtopping + " pizza will cost $" + maxcost);
- //Output: The cheapest pizza: The 40 inch pineapple pizza will cost $33.0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement