parseint - Java input/output confusion -
i writing program , need input value index, index should composite, e.g 44gh. question is, how make program not crash when ask user input , want display it?
i have been looking answer in site, integer or string type. if can help, appreciated.
scanner s input = new scanner(system.in); private arraylist<product> productlist; system.out.println("enter product"); string product = s.nextline(); system.out.println("input code product e.g f7pp"); string code = s.nextline(); } public void deleteproduct(){ system.out.println("enter code of product want delete "); string removed = input.nextline(); if (productlist.isempty()) { system.out.println("there no products removing"); } else { string astring = input.next(); productlist.remove(astring); } }
remove non digits char before casting integer:
string numbersonly= astring.replaceall("[^0-9]", ""); integer result = integer.parseint(numbersonly);
Comments
Post a Comment