Welcome to Dream.In.Code
Become a Java Expert!

Join 150,385 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,150 people online right now. Registration is fast and FREE... Join Now!




please help me this program

 
Reply to this topicStart new topic

please help me this program, i dont know about this String method...

al_buotan
20 Feb, 2008 - 01:25 AM
Post #1

New D.I.C Head
*

Joined: 8 Aug, 2007
Posts: 17


My Contributions
can any one help me this program?
there is an error that i cannot solve myself...


import java.util.Scanner;

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


String name;
char sex;
byte age;

System.out.print("Enter your name: ");
name = c.nextString();

System.out.print("Enter tour sex: ");
sex = c.next().charAt(0);

System.out.print("Enter your age: ");
age = c.nextByte();

System.out.println(name + "," + sex + "," + age + "years old.");
}
}
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Please Help Me This Program
20 Feb, 2008 - 02:31 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
so you won't take the pain to explain the problem. We need to find it and give you the solution too.
You won't mind reading psoting rules which asks you put your code in code tags.
User is offlineProfile CardPM
+Quote Post

lordms12
RE: Please Help Me This Program
20 Feb, 2008 - 11:12 AM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
QUOTE(al_buotan @ 20 Feb, 2008 - 02:25 AM) *
name = c.nextString();


The problem: nextString() is not defined method for the type Scanner

The solution:
CODE
name = c.nextLine();


This post has been edited by lordms12: 20 Feb, 2008 - 11:14 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month