Results 1 to 6 of 6
  1. #1
    abdul9383 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Can't fix my errors!

    Hello all,

    new to this forum and to java in general. Here's my code

    /*Compile :javac TestDrop.java
    * Run :java TestDrop
    * */

    //Header file section
    import java.util.Scanner;

    //Declare class name
    public class TestDrop
    {
    //main method
    public static void main(String[] args)
    {
    int a;
    int r=1;
    //Prompt the user input
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter an integer number: ");
    a= sc.nextInt();
    String str = Integer.toString(a);
    System.out.println("If drop the rightmost digit each then
    the new integers each: ");
    while(str.length()!=0)
    {
    //remove the rihtmost degit case
    str = str.substring(0,str.length()-r);
    //Display output
    System.out.print(", "+str);
    }

    }

    }


    --------------------------------


    DropDigit.java:21: unclosed string literal
    System.out.println("If drop the rightmost digit each then
    ^
    DropDigit.java:21: ';' expected
    System.out.println("If drop the rightmost digit each then
    ^
    DropDigit.java:22: '(' or '[' expected
    the new integers each: ");
    ^
    DropDigit.java:22: illegal start of expression
    the new integers each: ");
    ^
    DropDigit.java:22: unclosed string literal
    the new integers each: ");

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Can't fix my errors!

    Java Code:
    System.out.println("If drop the rightmost digit each then
    the new integers each: ");
    This confuses the compiler; literal Strings can't span more than a single line; change it to this:

    Java Code:
    System.out.println("If drop the rightmost digit each then the new integers each: ");
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    abdul9383 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: Can't fix my errors!

    Thanx for the response but still couldn't fix the errors.

    Got to look harder i guess :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Can't fix my errors!

    Quote Originally Posted by abdul9383 View Post
    Thanx for the response but still couldn't fix the errors.

    Got to look harder i guess :)
    Yup, but if you're still stuck after the hard thinking, feel free to post here again (including the relevant parts of the code and the error messages please).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    abdul9383 is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Re: Can't fix my errors!

    import java.util.Scanner;


    public class dropDigit {

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter an integer: ");
    int x = sc.nextInt();
    String s = Integer.toString(x);
    s = s.substring(0,s.length()-1);
    System.out.println("The new integer without the right most digit is "+s);
    while(str.length()!=0)
    {
    //remove the rihtmost degit case
    str = str.substring(0,str.length()-r);
    //Display output
    System.out.print(", "+str);
    }
    }
    }
    }

    -----------------------------

    down to one error: dropDigit.java:23: class, interface, or enum expected

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Can't fix my errors!

    If I counted correctly, you have one right curly bracket too many at the end of your file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Gui with errors
    By scooter24 in forum New To Java
    Replies: 2
    Last Post: 07-04-2011, 06:29 PM
  2. Many Errors After Do...While
    By jae5086 in forum New To Java
    Replies: 6
    Last Post: 04-03-2011, 08:15 PM
  3. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  4. Help with three errors -.-
    By Insomniac Riot in forum New To Java
    Replies: 5
    Last Post: 03-30-2010, 07:52 PM
  5. Replies: 3
    Last Post: 03-08-2009, 02:51 AM

Posting Permissions

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