Wednesday, 15 February 2012

Correct User Input in Java -



Correct User Input in Java -

am working on problem, basic code shown below, takes 4 possible inputs user, , produces response based on 1 input. need add together test validate 1 of 4 possible answers has been input.

i know how compare 2 of 4 inputs not 4 @ once, can give me idea? prefer figure out actual code myself pointer in right direction beneficial.

so clarify how - if input except "bill, circular, postcard or letter" produce error message x

system.out.println("what type of letter has been received?"); system.out.println("bill, circular, postcard or letter"); string letter = kybd.nextline(); { if (letter.equalsignorecase("bill")) { system.out.println("bills must paid"); } else if (letter.equalsignorecase("circular")) { system.out.println("circulars thrown away"); } else if (letter.equalsignorecase("postcard")) { system.out.println("postcards set on wall"); } else if (letter.equalsignorecase("letter")) { system.out.println("personal letters read , have replies written them"); } }

if (letter.equalsignorecase("bill")) { system.out.println("bills must paid"); } else if (letter.equalsignorecase("circular")) { system.out.println("circulars thrown away"); } else if (letter.equalsignorecase("postcard")) { system.out.println("postcards set on wall"); } else if (letter.equalsignorecase("letter")) { system.out.println("personal letters read , have replies written them"); }else{ system.out.println("error"); }

java

No comments:

Post a Comment