java - How do I end a program if a char the user entered a "." or a "-"? -
we're updating our previous lab , 1 of requirements if user enters '.' or '-' have output message should run programme 1 time again , programme exits.
this have far. i'm not sure if have utilize loops program.
system.out.print("\t come in employee number: "); employeenumber = keyboard.next().charat(0); if (employeenumber == '.' && employeenumber == '-'){ system.out.println("\t invalid employee number."); system.out.println("\t please run programme again."); system.out.println("thank using \"temple human resources\""); system.exit(0);
also, variable employeenumber char.
on line 3, within if statement, there should conditional-or operator. compares if either status adjacent true or false. if either 1 true, whole status set value of true.
if (employeenumber == '.' || employeenumber == '-'){
you may want instead, because looks through every single character of string , tells if true or false through boolean.
string employeenumber = keyboard.next(); boolean works = true; for(int = 0; < employeenumber.length(); a++) { if (employeenumber.charat(a) == '.' || employeenumber.charat(a) == '-'){ works = false; } } if(!works) { system.out.println("\t invalid employee number."); system.out.println("\t please run programme again."); system.out.println("thank using \"temple human resources\""); system.exit(0); }
conditional-and operators represented "&&" , set status true, if joined expressions result true.
java
No comments:
Post a Comment