Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Why isn't this code working?

    This is the code:


    import Java.util.Scanner

    public class Myknowledgeof_feb2012 {
    public static void main(String[] args) {
    java.util.Scanner sc=new Scanner (System.in);

    System.out.println("How are you doing?") ;

    String s= sc.nextLine();
    System.out.print("You are feeling (s)") ;

    }

    }


    I know its rudimentary and basic, but I'm a beginner. But seriously: Eclipse says that "Scanner cannot be resolved to a type". I dunno. Please help! This basic thing will allow me to continue my at-home studies!

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,901
    Thanks
    46
    Thanked 202 Times in 201 Posts
    I did not get any errors when I compiled you code that you posted... the only thing is it printed (s)... try this to get the correct string formatting
    Code:
    	Scanner keyboard = new Scanner(System.in);
    	System.out.println("How are you today?");
    	String demo = keyboard.nextLine();
    	System.out.printf("You are feeling %s", demo);

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    Funnyjoe66 (02-21-2012)

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Tnx!

    Thank-you! I wasn't sure how to imbed a value into a string, so I tryed that - and it worked. TNX!


  •  

    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
    •