fork download
  1. import java.util.Scanner;
  2. class Jtutorial1 {
  3. public static void main(String args[]){
  4. Scanner input = new Scanner(System.in);
  5.  
  6. //int i= 5; i(5);
  7. //int anArray[] = new int[5];
  8.  
  9. //anArray[ | | | | ];
  10. //anArray[0|0|0|0|0]; // initialize to 0
  11. //anArray[0|1|2|3|4]; // index. 0th, 1st, 2nd, 3rd, 4th
  12. //anArray[1|2|3|4|5]; //
  13. //anArray[ | |3| | ]; // 3
  14.  
  15. System.out.println("\nHow many items would you like to enter? : ");
  16. int x = input.nextInt(); //3
  17.  
  18. int itemArray[] = new int[x];
  19. double itemCost[] = new double[x];
  20.  
  21. for (int i = 0; i < itemArray.length; i++){ // initializing arrays to 0
  22. itemArray[i] = 0; // [i] Subscript.
  23. itemCost[i] = 0; // anArray[2] i=2 anArray[i]
  24. //itemArray / itemCost[ 0 | 0 | 0 ] // 0, 1, 2
  25. }
  26.  
  27. for(int i=0; i< itemArray.length; i++){
  28. System.out.println("\nEnter the unique, item ID: ");
  29. itemArray[i] = input.nextInt();
  30.  
  31. System.out.println("\nEnter the cost for that item: ");
  32. itemCost[i] = input.nextDouble();
  33. }
  34. System.out.println();
  35. System.out.println();
  36. System.out.println("Price list: ");
  37. for(int i=0; i < itemArray.length; i++){
  38. System.out.println("The value of i is: " + i + " Item Number: " + (itemArray[i]) + " = $" + itemCost[i]);
  39. }
  40.  
  41.  
  42.  
  43. }//end main
  44. }//end class
  45.  
  46.  
  47.  
  48. //Create an array, to enter user entered numbers.
  49.  
  50. //10
  51.  
  52. //a, a, a, a, c, c, c, d, f, g
  53.  
Success #stdin #stdout 0.08s 213440KB
stdin
3
19
20.74
16
17.89
14
22.97
stdout
How many items would you like to enter? : 

Enter the unique, item ID: 

Enter the cost for that item: 

Enter the unique, item ID: 

Enter the cost for that item: 

Enter the unique, item ID: 

Enter the cost for that item: 


Price list: 
The value of i is: 0  Item Number: 19 = $20.74
The value of i is: 1  Item Number: 16 = $17.89
The value of i is: 2  Item Number: 14 = $22.97