exception - Java.Lang.Stringindexoutofboundsexception index out of range (0) -
Each time the program tries to loop, the error "java.lang.stringindexoutofboundsexception" comes up and put
key = choice.charAt (0);
Do anyone know why this happens? I am new to programming and this is stumped to me. Thanks for any help. Any solution to this problem will be amazing
import java.util.Date; Import java.util.Scanner; Public class assignment 2 {public static zero main (string ARGS []) {Scanner = New scanner (system.); Date = new date (); Double wine = 13.99; Double beer 6 = 11.99; Double beer 12 = 19.99; Double beer 24 = 34.99; Double Spirient = 25.99; Double Spirit 1000 = 32.99; Int drink = 0; Double winital = 0.0; Double Grandotle = 0.0; Double GST = 0.0; String full = ""; String options; Four = ''; Double deposit 750 = 0.10; Double deposit = 1000 = 0.25; System.out.println ("------------------------------ \ n" + "*** Joshi's Liquer Mart You are welcome *** \ n today's date is "+ date"); Println ("----------------------------- ------- \ n "); Do {if! = 'W' & amp; ki! = 'B' & amp; amp; amp; ki! = 'S') {System.out. Print ("Wine is $ 13.99 \" Bayer 6 pack is $ 11.99 \ n "+" Beer 12 pack is $ 1.99 \ "Beer 24 Pack $ 34.99 \" Safijets is 750 ml $ 25.99 \ n "+" Spirits is 100ml $ 32.99 \ nImons are being purchased? \ N "+" For wine for beer, for beer and S spirits for B, or to leave x: ");} likes = k.nextLine ( ); = Liked Art (0); Switch (Key) {Case 'W': {System.out.print ("How many bottles are being purchased:"); Wineparchs = KNXIN (); Println (); Wineot = Wine * Wine purchase; GST = Vintotal * 0.05; Vintotal + = GST; System.out.println ("+ + + + + + + Waste slip +", which includes "+" GST and Deposit "+ Vinal"); System.out.print ("Is this customer order complete?" (Y / N) "); Complete = k.next (); break; }}} While (of! = 'X');
error means that the index "0" is outside the string limit To correct the user typed in any input, such as when you start the program and press the enter
key, just add the following lines of code:
likes = k.nextLine (); If (help.size ()> 0) {// process results} other {// ignoring the result}
I know that it helps!
Comments
Post a Comment