Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

Strings

Posted on February 10, 2021 By William Jojo
Uncategorized
public class Strings {
  
  public static void print_array(int[] potato) {
    int x;
    
    for (x = 0; x < potato.length; x++) {
      int y = 0;
      System.out.println("potato["+x+"] = " + potato[x]);
    }
  }
  
  public static void main(String[] args) {
  
    double cost = 0.0, price, sub;
    int count;
    
    for (String a : args) {
      System.out.println(a);
      
      String parts[] = a.split("@");
      for ( String p : parts)
        System.out.println(p);
      
      
      count = Integer.parseInt(parts[0]);
      price = Double.parseDouble(parts[1]);
      
      sub = count * price;
      System.out.printf("%d @ %.2f = %.2f%n", count, price, sub);
      cost = cost + sub;
    }
    
    System.out.printf("The total cost is $%.2f%n", cost);
  }
}

Post navigation

❮ Previous Post: TED, Podcasts and Text on Technology, Design and Learning
Next Post: bits ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.