Links
Portal |  Forum | Core Values | 
MindRomp Forum  

FAQ Janitors Arcade
Go Back   MindRomp Forum > Community > Rompus Room

Rompus Room Bring all your toys to share

Reply
 
Thread Tools Display Modes
Old 19th June 2015, 11:47 PM   #259245  /  #1
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

JAVAaaaaaaargh

So. Anyone speak java here?

I'm doing an online course (from Finland! take that Imp!) and I'm a beginner.

The problem is as follows: I need to have a program that asks user for a number and then tells user if it already is in the list. It *seems* to work but when I submit it I get a fail. The "info" messages about why it fails are gobbledegook, that goes without saying.

What am I doing wrong?


import java.util.ArrayList;
import java.util.Scanner;

public class MoreThanOnce {

public static boolean moreThanOnce(ArrayList<Integer> list, int searched) {
for (int number : list) {
if (list.contains((searched)) ) {
return true;
}
}
return false;
}

public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(3);
list.add(2);
list.add(7);
list.add(2);

System.out.println("Type a number: ");
int number = Integer.parseInt(reader.nextLine());
if (moreThanOnce(list, number)) {
System.out.println(number + " appears more than once.");
} else {
System.out.println(number + " does not appear more than once. ");
}
}
}
__________________
I thought I was in a bad mood but it's been a few years so I think this is who I am now
nostrum is offline   Reply With Quote topbottom
Old 19th June 2015, 11:48 PM   #259246  /  #2
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

fake ETA I need to use the moreThanOnce method, as that is what I'm supposed to be learning right now
__________________
I thought I was in a bad mood but it's been a few years so I think this is who I am now
nostrum is offline   Reply With Quote topbottom
Old 19th June 2015, 11:51 PM   #259249  /  #3
Imp
Inanimate bowl of pasta
 
Imp's Avatar
 

Read my posts with the following stupid accent: Waddle waddle
Nerd.
Imp is offline   Reply With Quote topbottom
Old 20th June 2015, 12:06 AM   #259252  /  #4
gib
them days are gone, boy
 
gib's Avatar
 

Read my posts with the following stupid accent: the thin one out of Laurel & Hardy
r: gray gray gray gray; -moz-border-radius: 0px 0px 0px 0px; } table.sample td { border-width: 1px 1px 1px 1px; padding: 1px 1px 1px 1px; border-style: inset inset inset inset; border-color: gray gray gray gray; -moz-border-radius: 0px 0px 0px 0px; }
Tagsybil thread
__________________
communicating my inner something since 2017
gib is offline   Reply With Quote topbottom
Old 20th June 2015, 12:07 AM   #259253  /  #5
Sybil
Self-perpetuating meltdown
 
Sybil's Avatar
 

Quote:
Originally Posted by gib View Post
r: gray gray gray gray; -moz-border-radius: 0px 0px 0px 0px; } table.sample td { border-width: 1px 1px 1px 1px; padding: 1px 1px 1px 1px; border-style: inset inset inset inset; border-color: gray gray gray gray; -moz-border-radius: 0px 0px 0px 0px; }
Tagsybil thread
That's not a thing
__________________
Sybil is offline   Reply With Quote topbottom
Old 20th June 2015, 12:13 AM   #259254  /  #6
Carlsson
kitchen sink garbage disposal
 
Carlsson's Avatar
 

Read my posts with the following stupid accent: Sweden
Carlsson is offline   Reply With Quote topbottom
Old 20th June 2015, 12:19 AM   #259259  /  #7
nostrum
too boring to be considered weird
 
nostrum's Avatar
 



and @ gib tag:
__________________
I thought I was in a bad mood but it's been a few years so I think this is who I am now
nostrum is offline   Reply With Quote topbottom
Old 20th June 2015, 12:20 AM   #259260  /  #8
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

fake ETA thanks for all the help so far!
__________________
I thought I was in a bad mood but it's been a few years so I think this is who I am now
nostrum is offline   Reply With Quote topbottom
Old 20th June 2015, 12:20 AM   #259261  /  #9
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

Quote:
Originally Posted by Imp View Post
Nerd.
you just fucking wait until I reveal my new Amazing Mafia Spreadsheet
__________________
I thought I was in a bad mood but it's been a few years so I think this is who I am now
nostrum is offline   Reply With Quote topbottom
Old 20th June 2015, 01:11 AM   #259290  /  #10
borealis
poikilothermic
 
borealis's Avatar
 

Read my posts with the following stupid accent: Canada
I'd help you if you wanted to know the difference between Canada Mayflower, also called False Solomon's Seal, and Mayflower, also called Trailing Arbutus.

This java thing though... does it have caffeine?
__________________
borealis is offline   Reply With Quote topbottom
Old 20th June 2015, 01:16 AM   #259293  /  #11
MSG
Ol' Zipperlaig
 
MSG's Avatar
 

Read my posts with the following stupid accent: Nyfb
Your not supposed to capitalise the I in line 6 you dummy
MSG is offline   Reply With Quote topbottom
Old 20th June 2015, 01:22 AM   #259297  /  #12
Imp
Inanimate bowl of pasta
 
Imp's Avatar
 

Read my posts with the following stupid accent: Waddle waddle
Quote:
Originally Posted by nostrum View Post
Quote:
Originally Posted by Imp View Post
Nerd.
you just fucking wait until I reveal my new Amazing Mafia Spreadsheet
Probably doesn't even have a Steve.
Imp is offline   Reply With Quote topbottom
Yay from
Tere (20th June 2015)
Old 20th June 2015, 01:34 AM   #259301  /  #13
MartinM
Interdimensional Heckler
 
MartinM's Avatar
 

Looks to me like your code should run, but doesn't do what it's supposed to do. Your moreThanOnce method actually tests whether or not the number is present in the list at all, not whether it's present more than once.

What error messages are you getting?
MartinM is offline   Reply With Quote topbottom
Old 20th June 2015, 02:46 AM   #259373  /  #14
Timewave
Senior Member
 
Timewave's Avatar
 

Read my posts with the following stupid accent: IN MY HEAD (MOSTLY)
Quote:
Originally Posted by MartinM View Post
Looks to me like your code should run, but doesn't do what it's supposed to do. Your moreThanOnce method actually tests whether or not the number is present in the list at all, not whether it's present more than once.

What error messages are you getting?
I thought that's what nos was testing?
Is the number in the array or not?
Yes or no?
__________________
this ol' world keeps spinning round, it's a wonder tall trees ain't laying down, comes a time.
Timewave is offline   Reply With Quote topbottom
Old 20th June 2015, 02:50 AM   #259376  /  #15
Timewave
Senior Member
 
Timewave's Avatar
 

Read my posts with the following stupid accent: IN MY HEAD (MOSTLY)
I'm doing an online course (from Finland! take that Imp!) and I'm a beginner.

The problem is as follows: I need to have a program that asks user for a number and then tells user if it already is in the list. It *seems* to work but when I submit it I get a fail. The "info" messages about why it fails are gobbledegook, that goes without saying.

What am I doing wrong?


This part says that the return should be a simple yes or no.
IS the number in the list or not.
__________________
this ol' world keeps spinning round, it's a wonder tall trees ain't laying down, comes a time.
Timewave is offline   Reply With Quote topbottom
Old 20th June 2015, 02:55 AM   #259382  /  #16
Timewave
Senior Member
 
Timewave's Avatar
 

Read my posts with the following stupid accent: IN MY HEAD (MOSTLY)
Your right this part is not asking if the number is already there.
It is asking if the number is there more than once.
In other words is there a duplication?


System.out.println("Type a number: ");
int number = Integer.parseInt(reader.nextLine());
if (moreThanOnce(list, number)) {
System.out.println(number + " appears more than once.");
} else {
System.out.println(number + " does not appear more than once. ");
}
__________________
this ol' world keeps spinning round, it's a wonder tall trees ain't laying down, comes a time.
Timewave is offline   Reply With Quote topbottom
Old 20th June 2015, 02:56 AM   #259387  /  #17
MartinM
Interdimensional Heckler
 
MartinM's Avatar
 

That's what her description of the problem says, yes. Her code says otherwise. So one or the other is wrong.
MartinM is offline   Reply With Quote topbottom
Old 20th June 2015, 03:02 AM   #259398  /  #18
Timewave
Senior Member
 
Timewave's Avatar
 

Read my posts with the following stupid accent: IN MY HEAD (MOSTLY)
so the routine has to be;
Enter a number.
Find the number, ONCE (or return number not found?)
Then scan the list a second time to see if it is there a second time?

Check what the function 'moreThanonce' does?

Um?
Stupid question. the array you have set up to test your sub routine on?
Does it have nay integers twice?
__________________
this ol' world keeps spinning round, it's a wonder tall trees ain't laying down, comes a time.
Timewave is offline   Reply With Quote topbottom
Old 20th June 2015, 03:03 AM   #259400  /  #19
Timewave
Senior Member
 
Timewave's Avatar
 

Read my posts with the following stupid accent: IN MY HEAD (MOSTLY)
Quote:
Originally Posted by MartinM View Post
That's what her description of the problem says, yes. Her code says otherwise. So one or the other is wrong.
Yes, that's right Martin, Sorry.
__________________
this ol' world keeps spinning round, it's a wonder tall trees ain't laying down, comes a time.
Timewave is offline   Reply With Quote topbottom
Old 20th June 2015, 03:15 AM   #259413  /  #20
OmicronPersei8
Declared candidate for Best Poster 2017 of the fuckin decade
 
OmicronPersei8's Avatar
 

Read my posts with the following stupid accent: Gib's
My in tro cs course used java this looks familiar but it was 5 years ago so I forgot the main shit and syntax


Hope this helped
__________________
I am Lrrr, ruler of the planet OmicronPersei8.

Jerome: My mistake.
OmicronPersei8 is offline   Reply With Quote topbottom
Old 20th June 2015, 03:22 AM   #259424  /  #21
MSG
Ol' Zipperlaig
 
MSG's Avatar
 

Read my posts with the following stupid accent: Nyfb
it did
__________________
Over 19,000 more posts than Prince Humperdinck
MSG is offline   Reply With Quote topbottom
Old 20th June 2015, 03:30 AM   #259433  /  #22
oblivion
Asylum
 
oblivion's Avatar
 

Read my posts with the following stupid accent: Norton's Empire
I initially read the thread title as JAWJAAAAAAH

was confused.
oblivion is offline   Reply With Quote topbottom
Yay from
Majiffy (21st June 2015)
Old 20th June 2015, 05:09 AM   #259513  /  #23
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

Quote:
Originally Posted by MartinM View Post
Looks to me like your code should run, but doesn't do what it's supposed to do. Your moreThanOnce method actually tests whether or not the number is present in the list at all, not whether it's present more than once.

What error messages are you getting?
Ah. I hadn't thought about that at all. I guess it's asking if the input number is in the list more than once. I see. Hmm I'll go away and think if I can rejig it. Traveling interstate and avoiding murderers if possible. Will revisit when on my laptop on Monday.

Thanks!
nostrum is offline   Reply With Quote topbottom
Old 20th June 2015, 05:09 AM   #259514  /  #24
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

Quote:
Originally Posted by oblivion View Post
I initially read the thread title as JAWJAAAAAAH

was confused.
If you can help with that I'd also appreciate it
nostrum is offline   Reply With Quote topbottom
Old 20th June 2015, 05:10 AM   #259516  /  #25
nostrum
too boring to be considered weird
 
nostrum's Avatar
 

Quote:
Originally Posted by OmicronPersei8 View Post
My in tro cs course used java this looks familiar but it was 5 years ago so I forgot the main shit and syntax


Hope this helped
Thanks OP you're all over this as any nerd should be
nostrum is offline   Reply With Quote topbottom
Reply

  MindRomp Forum > Community > Rompus Room

Tags
penis penis penis

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:33 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2011-2018 MindRomp.org