Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,029 members, 7,956,820 topics. Date: Monday, 23 September 2024 at 07:58 PM |
Nairaland Forum / Science/Technology / Programming / Java: How To Go To A Line If A Wrong Value Is Inputted (1333 Views)
Java: How Can Write A File on Internet To A SQL Blob Field Directly? / Who Has Dietel's Java How To Program 10th Edition Online Chapters? / Who Has "Java How To Program 10th Edition " By Paul Dietel? (2) (3) (4)
Java: How To Go To A Line If A Wrong Value Is Inputted by abumeinben(m): 2:25pm On Jul 21, 2016 |
Hi hackers! Ive been having this little issue on this code. I'm new to programming. If a wrong value if inputted, I want the program to run until the right value is inputted. Kindly assist. Java code:
Thanks cc: Emmach10 Dreadlord larisoft lekropasky DonSegmond codemarshal08 omoelu1 |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 3:17pm On Jul 21, 2016 |
Code doesnt look good here. So send me the code to my mail. Meanwhile, you can use a do-while or while loop to run the code till the user gets the right input! |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 3:34pm On Jul 21, 2016 |
Thats simple. First of all you have to handle the exception that will occur if the user did not enter an integer then you have to validate the integer as the user enters it to make sure if its within 0 and 6 before you pass on the integer to the switch case to determine the date. This could be done with an if statement inside a while statement or with a do-while statement. Another alternative will be to put a code snipet inside the default case that returns the user the begining of the code thanks. I could have edited the code for you but am using a poor browser that doesnt support javascript so cant select code view. |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 4:03pm On Jul 21, 2016 |
abumeinben: Input this before the switch statement.
1 Like |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 4:03pm On Jul 21, 2016 |
abumeinben: Input this before the switch statement.
|
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by abumeinben(m): 6:42pm On Jul 21, 2016 |
Emmach10: Will try as soon as I ..tnx |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 7:09pm On Jul 21, 2016 |
abumeinben: You are welcomed. Note: i didnt test the code so try it and modify to you own satisfaction! |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Nobody: 7:15pm On Jul 21, 2016 |
thank God my name was not mentioned, trolls away silently to the backbench watching the JAVA dudes at work. . . |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 9:28pm On Jul 21, 2016 |
dhtml18: Lolzz. What languages can you program in and what are your skills? |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Nobody: 10:28pm On Jul 21, 2016 |
Emmach10:E gba mi o / O'di egwu / osanobuame / santa maria!! See me see wahala. Okay, i ain't got a skillset other than TROLLING. |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 10:54am On Jul 22, 2016 |
dhtml18: Lolzz, i dont mean any insult ooh! |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Nobody: 12:07pm On Jul 22, 2016 |
me i just dey play play ni o |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by lekropasky(m): 3:36pm On Jul 23, 2016 |
Am sorry for replying this late. Ok...to the real business. I can see some error here, you are already overriding the input entered by the user inside your switch statement. int day = input.nextInt(); //loop indefinitelly while(true){ //put your switch statement here. Switch(day){ case 0: System.out.print("The day is Sunday" break; //test other cases here.... default: System.out.print("you haven't entered a correct value. Please Try again" } //then, outside your switch statement, put this, day = input.nextInt(); //to break of this loop, simply put a condition here...e.g, if you want to break when the user enter 9. if(day==9){ System.out.print("Thank You for using this program" break; } } |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 12:50am On Jul 25, 2016 |
lekropasky: this will definitely result to a logical error called infinite loop |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by yorex2011: 1:48pm On Jul 25, 2016 |
This is one way of doing it i'm just a beginner too so i'm just trying to be clever here
|
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by Emmach10(m): 9:26am On Jul 26, 2016 |
yorex2011: You are definitely learning with Java How To Program by Paul Deitel and Associates Right? |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by yorex2011: 9:39am On Jul 26, 2016 |
Emmach10:Sentinel definitely gave me away lol |
Re: Java: How To Go To A Line If A Wrong Value Is Inputted by lekropasky(m): 11:18am On Jul 26, 2016 |
Emmach10:Nope, I have not finished it. the line // day = input.nextInt(); // will cause the loop to wait for user input before continuing to the next Iteration. see the modified version to break out of the loop |
(1) (Reply)
Complete Primary And Secondary Website Needed / Forloop Valley For Programmers / .
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 43 |