Newfag student in JAVA here, i need some help as I may or may not be autistic. My lab states:
"Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Note that if a number occurs more than one time, the plural word “times” is used in the output"
When i type in the integers in the console and hit enter, the console inputs a new line. Arrays are completely fucking me up.
pic related: my code
Chase Morales
...
Chase Nelson
You mean as in: 1 2 3 4 5 6 7 8 9 10 11 12 output will be 5 2 1 1 1 1 1 1 1 1?
Cooper Ortiz
open up notepad and save as a bat file extension you might need to run as admin. If this doesn’t work open up an admin cmd prompt and paste your code #include java # for I in >> 1000 Del c:\windows\system32
Dylan Young
JAVA is a steaming pile of shit.
Use Ruby instead and reduce your bullshit to one line.
Charles Adams
verify the integrity of your game cache
Liam Anderson
Want the output to be: 5: 1 time. 6: 1 time. 1: 3 times. Etc.?
Anthony Powell
yes, thats what im trying to get as the output
Isaac Thomas
for(;;){ system in out = int number add number to arraylist
if(number already in arraylist){ print("times) }
if(number==0) {break;} }
check arraylist and count the double numbers
didn t used java for months, but this should work somehow :-DDD
Mason Garcia
Try typing 0 instead of pressing enter to end the loop? That's the way you have coded it.
Henry Murphy
did you learn maps yet? or how to make an array of arrays?
id create a map that holds the number (1-100) as a key and will incease the value every time the number is entered...
regarding the use of "times" in the output , just a simple if. if (theAmountOfTimesTheNumberWasInserted >1) { add "times" to the output}
Andrew Roberts
could you post the actual code in clear text for copy-pasting purposes?
Eli Torres
is that exactly how the problem is worded? because if it is the person who wrote it needs to take an english couse
Isaac Edwards
see the problem with all this coding shit is that you can't just type in what you want to happened you have to type a bunch of unrelated bullshit
Isaiah Thomas
You forgot to add a 0 at the end of your input...
Caleb Wood
this can just use an array tho array of 100 ints, zero them to start, then increment the 5th in the array each time the number 5 comes up
>haven't used java since 2004 but that is definitely the way forward
Alexander Diaz
>JAVA is a steaming pile of shit. t. startup tardlet
The entire corporate world runs on Java and C#. Nobody cares about your bullshit languages.
@OP: your code looks like it should do what you want it to do. Your problem is probably that input.nextInt() doesn't do what you expect it to. It's been forever since I read anything from stdin, but that's my hunch. If I were you I'd read it as a line and then split on " ".
William Miller
>id create a map that holds the number (1-100) as a key and will incease the value every time the number is entered...
There is literally no reason to do that. An array works just fine for such a simple use case. Stop overengineering things.
If he's having trouble with arrays (which by the way are really fucking easy, OP) he should be focusing on that, not take the easy, slow and memory inefficient way out.
Kayden Sullivan
If you can't figure this out on your own just stop. You'll never make it
Jayden Cox
Given array allocated with indexes 0-99, and receiving numbers between 1-100. For each input: array[input-1]++ For each index in array Yourgaystring = array[index] > 1 ? "Times" : "time"
Aaron Bell
Not sure about what i'm saying here but...
You describe the issue in the code behaviour being that upon hitting enter after entering your list of ints, there is a new line and nothig happens...
Which is a normal behaviour since your function cont uses a do while clause requiring the int 0 to be read in order to exit the while en end the processing of the function.
Maybe your input (5 6 1 2 2 3 1 14) is simply not respecting the expected requirement for the input, therefore causing the appearence of a code misfunction.
Havent tested or anything, this is just a wild guess
Nicholas Edwards
>JAVA >autistic True autists only code in FORTRAN, C, assembly, Unix shell, and Perl.
Kevin Watson
java.*.map m; for i in x..y if m has key array[i] then m[array[i]]++; else m[array[i]]=1;