This java code compiles, but is wrong. Can you tell me what is wrong with it? -
here code, below. need this, have no clue wrong it. compiles cleanly, said, whenever run it, fails execute. thanks!
import java.util.scanner; public class whatthe { public static void main(string[ ] args){ scanner scan = new scanner(system.in); int i; string s; char c; system.out.print("please enter number: "); = scan.nextint( ); system.out.println(i); system.out.println( ); system.out.print("please input 3 words separated spaces: "); s = scan.next(); system.out.println(s); system.out.println( ); system.out.print("please input something: "); s = scan.nextline(); system.out.println(s); system.out.println( ); system.out.print("please enter number: "); = scan.nextint( ); system.out.println(i); system.out.println( ); system.out.print("please input word: "); s = scan.nextline(); c = s.charat(0); system.out.println(c); system.out.println( ); system.out.println("good bye"); } }
try this:
scanner scan = new scanner(system.in); int i; string s; char c; system.out.print("please enter number: "); = scan.nextint( ); scan.nextline(); system.out.println(i); system.out.println( ); system.out.print("please input 3 words separated spaces: "); s = scan.nextline(); system.out.println(s); system.out.println( ); system.out.print("please input something: "); s = scan.nextline(); system.out.println(s); system.out.println( ); system.out.print("please enter number: "); = scan.nextint( ); scan.nextline(); system.out.println(i); system.out.println( ); system.out.print("please input word: "); s = scan.nextline(); c = s.charat(0); system.out.println(c); system.out.println( ); system.out.println("good bye");
so, after each scan.nextint(), scan.nextline() can proceed.
Comments
Post a Comment