Dont accept String name | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Dont accept String name

import java.util.Scanner; class A { int hno; String city,state; void getdata() { Scanner sc = new Scanner(System.in); System.out.println("\n\t enter the house number"); hno = sc.nextInt(); System.out.println("\n\t enter the city name"); city = sc.nextLine(); System.out.println("\n\t enter the state name"); state = sc.nextLine(); } void display() { System.out.println("House no : "+hno +""+"\n"+ "City name : "+city +""+"\n"+ "state name: "+state); } } public class SimpleI extends A { public static void main(String[] args) { SimpleI hcs = new SimpleI(); hcs.getdata(); hcs.display(); } }

13th Aug 2017, 9:06 AM
KANHAYA TYAGI
KANHAYA TYAGI - avatar
3 Answers
+ 3
I don't understand the question. Anyway, if there's an issue with your code its probably how you're putting in the input. Add a blank nextLine() after taking the house number as input. Like so: sc.nextLine(); city = sc.nextLine(); This is since the input stream hasn't move to the next line yet after you took the int as input. So you could also just input it like this instead of adding the extra nextLine(): 7261 myWord LastThing instead of: 7261 myWord LastThing
13th Aug 2017, 3:23 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
wait i will check
13th Aug 2017, 3:29 PM
KANHAYA TYAGI
KANHAYA TYAGI - avatar
+ 1
thankew sir.....
13th Aug 2017, 3:33 PM
KANHAYA TYAGI
KANHAYA TYAGI - avatar