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 5 of 5

Thread: Removing the import function.

  1. #1
    Member melki0795's Avatar
    Join Date
    Nov 2013
    Location
    Malta
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Removing the import function.

    Hi!

    I just an exam and I was given a program where it imported the the java util scanner.

    The code was something like this

    import java.util.Scanner;
    class A {
     
    public static void main(String[] s){
     
    Scanner sc = new Scanner(System.in);
    name = getName(sc);
    System.out.println(name);
    }
     
    static String getName(Scanner sc) {
    String name;
    System.out.println("Please enter the name ");
    name = sc.nextLine();
    return name;
    }
    }

    The question asked me to remove the import at the top of the program. Is it correct if I did:

     
    class A {
     
    public static void main(String[] s){
     
    java.util.Scanner sc = new Scanner(System.in);
    name = getName(sc);
    System.out.println(name);
    }
     
    static String getName(java.util.Scanner sc) {
    String name;
    System.out.println("Please enter the name ");
    name = sc.nextLine();
    return name;
    }
    }

    Thank's in advance.


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Removing the import function.

    What happens when you compile your version?

  3. #3
    Member melki0795's Avatar
    Join Date
    Nov 2013
    Location
    Malta
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Removing the import function.

    don't have a java compiler with me, it was a written exam, not on a computer...

  4. #4
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Removing the import function.

    Quote Originally Posted by melki0795 View Post
    The question asked me to remove the import at the top of the program. Is it correct if I did:
    You have to fully "qualify" all occurrences of the Scanner class name, also in the instantiation expression.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  5. #5
    Member melki0795's Avatar
    Join Date
    Nov 2013
    Location
    Malta
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Removing the import function.

    Quote Originally Posted by andbin View Post
    You have to fully "qualify" all occurrences of the Scanner class name, also in the instantiation expression.

    So close

    Thanks

Similar Threads

  1. [SOLVED] Which is more efficient? "import java.package.subpackage" or "import java.package.*"
    By Andrew R in forum Java Theory & Questions
    Replies: 1
    Last Post: August 18th, 2013, 01:11 PM
  2. Removing A Vehicle
    By OllieDee in forum Object Oriented Programming
    Replies: 7
    Last Post: July 4th, 2013, 06:34 PM
  3. Best way of adding and removing?
    By J-moges in forum Java Theory & Questions
    Replies: 3
    Last Post: May 23rd, 2013, 01:43 PM
  4. Help with removing objects
    By Seacats in forum Object Oriented Programming
    Replies: 4
    Last Post: May 2nd, 2013, 08:32 AM
  5. Import if Import is Found, Else
    By blazedGinger in forum Java Theory & Questions
    Replies: 5
    Last Post: March 9th, 2013, 06:43 PM

Tags for this Thread