Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: simple program

  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default simple program

    i was told to write a program to test if the value is digit or not .. import java.util.Scanner;
    public class Test_For_Digit {

    public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
    System.out.println("enter any value of your choice ");
    double n = input.nextDouble();
    if (n >=0){

    System.out.println("you enter digit which is = " + n);

    }

    else{
    System.out.println("you eneter = " + n + " and its not a digit");
    }
    }

    } if i press alphabet it will trigger an error help me out

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: simple program

    Do you have any specific java programming questions?
    What happens when you try to compile and execute your program?
    Copy the full text of any messages and paste it here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple program

    The error is that instead of me to enter integer I enter string.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,383
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: simple program

    instead of me to enter integer I enter string.
    Yes, Strings are the normal input to a program from a keyboard. It is hard to enter integer values from the keyboard. "9" is a String not an integer
    The String input can be converted to an int be using some method like Integer.parseInt() or some of the Scanner class's methods
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Simple Program Help
    By TripleChickenJumpman in forum AWT / Java Swing
    Replies: 1
    Last Post: February 27th, 2014, 01:37 AM
  2. please help with simple program!!!
    By jokneez in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 14th, 2011, 10:42 AM
  3. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 03:43 PM
  4. simple program
    By Memb in forum Paid Java Projects
    Replies: 0
    Last Post: March 17th, 2010, 01:47 PM