• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

How can I add an index to each for loop?

 
Greenhorn
Posts: 2
C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi all. I need to write a program that creates and displays unique three-digit numbers using 1, 2, 3, 4. It also needs to count how many three-digit numbers there are (in this case 24), however I also want to add each indivual index to these 24 numbers. I tried keeping the indexes seperately however that only messed things up.
Thank you for your help.
 
Saloon Keeper
Posts: 9738
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not entirely clear on what you're looking for, but  here's a guess

int n = (i * 100) + (j * 10) + k;
 
Saloon Keeper
Posts: 5168
207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can leave out the complicated 'if (...)' as follows:



Edit: oops! Stupid me.... I misread the exercise. Apologizes for that!
 
Elsa Brown
Greenhorn
Posts: 2
C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I'm not entirely clear on what you're looking for, but  here's a guess

int n = (i * 100) + (j * 10) + k;



Thank you, but I'm not sure that that's quite right. I'm looking to number every three-digit-number until I reach 24. I tried following this however that didn't seem work out.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't call a class to create numbers Apples.
Please explain what you mean about numbering three‑digit integers. You already have an amount variable. Are you going to use that? I think you will find there are 4! = 24 such combinations of your three digits if they are all different. What is going wrong with your program? I got it to run successfully on JShell.
 
My, my, aren't you a big fella. Here, have a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic