Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Netbeans data entry

Netbeans data entry

Scheduled Pinned Locked Moved Java
javavisual-studiohelptutorialquestion
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aecordoba
    wrote on last edited by
    #1

    I'm beginning with java and I'm using NetBeans IDE 6.1 to edit, build and run my first sourcefiles and projects. The problems is when I need to enter data to my program. For example, look at the following code:

    package formattedprint;
    import java.util.*;

    public class Main {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

        System.out.println("Enter an integer number:\\n");
        int intNum = in.nextInt();
        
        System.out.println("Enter a string:\\n");
        String string = in.nextLine();
        
        System.out.println("------------------------------");
        System.out.printf("Integer number: %d%n", intNum);
        System.out.printf("Cadena: %s%n", string);
        System.out.println("------------------------------");
    }
    

    }

    When I run this code, there is not an input window. Only I can enter data in the "output window", and it seems to work in a bad way: When the program ask for the integer number and I enter 1 (for example), the program finish without ask for the string. This is the output window:

    init:
    deps-jar:
    Compiling 1 source file to /home/adrian/NetBeansProjects/FormattedPrint/build/classes
    compile:
    run:
    Enter an integer number:

    Enter a string:


    Integer number: 1
    Cadena:

    1
    BUILD SUCCESSFUL (total time: 6 seconds)

    I think, I'm doing something wrong. (May be I should open an input window, but I didn't find it.) Please, can somebody help me?

    [Adrián Córdoba]

    B 1 Reply Last reply
    0
    • A aecordoba

      I'm beginning with java and I'm using NetBeans IDE 6.1 to edit, build and run my first sourcefiles and projects. The problems is when I need to enter data to my program. For example, look at the following code:

      package formattedprint;
      import java.util.*;

      public class Main {
      public static void main(String[] args) {
      Scanner in = new Scanner(System.in);

          System.out.println("Enter an integer number:\\n");
          int intNum = in.nextInt();
          
          System.out.println("Enter a string:\\n");
          String string = in.nextLine();
          
          System.out.println("------------------------------");
          System.out.printf("Integer number: %d%n", intNum);
          System.out.printf("Cadena: %s%n", string);
          System.out.println("------------------------------");
      }
      

      }

      When I run this code, there is not an input window. Only I can enter data in the "output window", and it seems to work in a bad way: When the program ask for the integer number and I enter 1 (for example), the program finish without ask for the string. This is the output window:

      init:
      deps-jar:
      Compiling 1 source file to /home/adrian/NetBeansProjects/FormattedPrint/build/classes
      compile:
      run:
      Enter an integer number:

      Enter a string:


      Integer number: 1
      Cadena:

      1
      BUILD SUCCESSFUL (total time: 6 seconds)

      I think, I'm doing something wrong. (May be I should open an input window, but I didn't find it.) Please, can somebody help me?

      [Adrián Córdoba]

      B Offline
      B Offline
      BlackWolvix
      wrote on last edited by
      #2

      Hi, yep that was kinda weird or was just done for file reading. :S btw i dunno why are you using printf if you have the easier methods which are println and print :P however its ur decision but i find this is working XD anyways you can use this code: public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter an integer number:\n"); int intNum = in.nextInt(); System.out.println("Enter a string:\n"); //This will only read the first string aka the first name if u wish String string1 = in.next(); //This is for the last name if you wish String string2 = in.next(); System.out.println("------------------------------"); System.out.println("Integer number: " + intNum); System.out.println("Cadena: " + string1 + " " + string2); System.out.println("------------------------------"); } } The output: init: deps-jar: compile: run: Enter an integer number: 1 Enter a string: Jassim Makki ------------------------------ Integer number: 1 Cadena: Jassim Makki ------------------------------ BUILD SUCCESSFUL (total time: 6 seconds)

      BlaCk WolViX

      A 1 Reply Last reply
      0
      • B BlackWolvix

        Hi, yep that was kinda weird or was just done for file reading. :S btw i dunno why are you using printf if you have the easier methods which are println and print :P however its ur decision but i find this is working XD anyways you can use this code: public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter an integer number:\n"); int intNum = in.nextInt(); System.out.println("Enter a string:\n"); //This will only read the first string aka the first name if u wish String string1 = in.next(); //This is for the last name if you wish String string2 = in.next(); System.out.println("------------------------------"); System.out.println("Integer number: " + intNum); System.out.println("Cadena: " + string1 + " " + string2); System.out.println("------------------------------"); } } The output: init: deps-jar: compile: run: Enter an integer number: 1 Enter a string: Jassim Makki ------------------------------ Integer number: 1 Cadena: Jassim Makki ------------------------------ BUILD SUCCESSFUL (total time: 6 seconds)

        BlaCk WolViX

        A Offline
        A Offline
        aecordoba
        wrote on last edited by
        #3

        Thank you. I'll try your recommendations. P.S.: I was using printf method because it was recommended in the practice of the book I studying with (Core Java 2).

        [Adrián Córdoba]

        B 1 Reply Last reply
        0
        • A aecordoba

          Thank you. I'll try your recommendations. P.S.: I was using printf method because it was recommended in the practice of the book I studying with (Core Java 2).

          [Adrián Córdoba]

          B Offline
          B Offline
          BlackWolvix
          wrote on last edited by
          #4

          no problemo anytime buddy ;)

          BlaCk WolViX

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups