![]() |
Need to print output without arrays
Code:
import java.io.*;Hi I need to print out a summary of all items that was input was by the user.When the program runs it only prints the last input and not all.How do i get it to print all items without using arrays |
Re: Need to print output without arrays
You can declare a String variable and append the summary details(whatever it may be) to it for every item inside the loop.
Then you can print the variable outside the loop to view the summary of all the items. |
Re: Need to print output without arrays
Didnt I do that already.
String de,s,ic,st; Or can u elaborate a liitile on your suggestion cause i'm a bit confused thanks. |
Re: Need to print output without arrays
When asked if to enter more data and no is selected the final summary should be like this:
eg: 5 Rope k23/1 @ $12.34 Total $61.70 50 Nail 12/ewr @ $2.23 Total $111.50 Grand Total weight : Grand total cost: but its just printing the last statement entered. A little more info on my problem |
Re: Need to print output without arrays
You have calculated the values and displayed them inside the loop. You have displayed the summary outside the loop, where the variables that you declared will hold only the final value.
To have the details of all the items, you can have another variable, say str. For every loop, append the details(variables that you already declared) at the end of the variable 'str'. So, at the end of the loop, the variable 'str' will have all the items' details and you can print it. |
Re: Need to print output without arrays
If you could not understand yet, just let me know where you don't understand. I can explain.
|
Re: Need to print output without arrays
ok tell me if i'm catching on or that badly off lol. I should declare a new String variable eg. str.Then assign variables i want to print out
eg. str =( r+" "+ de +" "+ ic+" "+"@"+" "+c+" "+ " TOTAL $" + r*c) |
Re: Need to print output without arrays
Sorry but its my first time with java so forgive me lol
|
Re: Need to print output without arrays
You got my point. But the way you are doing is wrong.
So you can very well search the internet on how to append variables to another variable. Or you can also refer a JAVA book for that. :) This is the correct way for a beginner like you to get familiarized with any programming language. |
Re: Need to print output without arrays
took your advice but still looking for how to append variables to a variable
|
| All times are GMT +5.5. The time now is 01:55. |