Results 1 to 7 of 7
Like Tree3Likes
  • 3 Post By DarrylBurke

Thread: Converting Scanner into an int

  1. #1
    23scurtu is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Converting Scanner into an int

    Hey, so you don't wonder I'm a bit new to the java programming community. well anyway, I am trying to code a simple spambot to have to use for fun with friends and what not but, I had a problem. All my code was fine but, in the for loop It could not convert my scanner into a int, here's my code:

    import java.util.Scanner;

    class Test {
    public static void main(String[] args) {

    Scanner Spam=new Scanner(System.in);

    System.out.println(Spam.nextInt());

    for(int counter=0; counter=<Spam; counter++){


    {
    System.out.println("Victor");
    }
    }
    }
    }

    I haven't put in the JFrame yet because I'm going to do that later, but do you know how I could fix this problem? Please answer soon.

    Sincerely,
    Victor

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Converting Scanner into an int

    Please use [code] tags [/code] when posting code.

    You need to store the value returned by nextInt() into an int variable.
    Then test that variable, not the Scanner one.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Converting Scanner into an int

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Converting Scanner into an int

    Quote Originally Posted by 23scurtu View Post
    I am trying to code a simple spambot
    And you expect help from forum members with that?

    db
    awinston, kammce and Fubarable like this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Converting Scanner into an int

    This is some pretty dark magic you are dealing with here, mate.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  6. #6
    23scurtu is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: Converting Scanner into an int

    Quote Originally Posted by Tolls View Post
    Please use [code] tags [/code] when posting code.

    You need to store the value returned by nextInt() into an int variable.
    Then test that variable, not the Scanner one.
    Co how exactly would I accomplish that? What would I change/add?

  7. #7
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Converting Scanner into an int

    Quote Originally Posted by 23scurtu View Post
    Co how exactly would I accomplish that? What would I change/add?
    First, learn how to program in Java: The Java Tutorials

    Nobody here is going to help you terrorize your friends by spoon-feeding you pseudo-malicious code.
    Last edited by awinston; 08-15-2012 at 02:24 AM.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Converting
    By PhQ in forum New To Java
    Replies: 3
    Last Post: 08-21-2011, 06:28 PM
  2. Converting Scanner input to JOptionPane
    By Mideoan in forum New To Java
    Replies: 1
    Last Post: 03-10-2011, 12:26 AM
  3. converting hex to dec -
    By Symbiot in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 02:56 PM
  4. need help converting
    By sr20guy in forum New To Java
    Replies: 16
    Last Post: 04-02-2010, 02:07 PM
  5. Converting URL to URI
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 11:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •