Please help me with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me with this code

Please help me to solve the problem with this code https://code.sololearn.com/ci3njX8brM4P/?ref=app

12th Aug 2022, 9:07 AM
Adebayo Abdul Salam
Adebayo Abdul Salam - avatar
8 Answers
+ 2
Scanner scan = new Scanner(System.in); // not SystemIn
12th Aug 2022, 9:35 AM
Jayakrishna 🇮🇳
+ 2
Hi.....! it's: Scanner scan = new Scanner(System.in); and not Scanner scan = newScanner(Systemln); the method /**next()**/ retains the cursor in the same line after reading the input. replace it by /**nextLine()**/
12th Aug 2022, 11:21 AM
jurise mboumene
jurise mboumene - avatar
+ 2
replace this line /**String religion = scan.next();**/ by String religion = scan.nextLine(); and it will show worksip
12th Aug 2022, 6:17 PM
jurise mboumene
jurise mboumene - avatar
+ 1
Thanks but why do the worship do not show
12th Aug 2022, 5:31 PM
Adebayo Abdul Salam
Adebayo Abdul Salam - avatar
+ 1
Ok but I want to show that worship
13th Aug 2022, 6:41 AM
Adebayo Abdul Salam
Adebayo Abdul Salam - avatar
+ 1
/**try this code. remember to split multiple input in separate line when you press run your input should be like that : mousa muslin brique **/ import java.util.Scanner ; public class Answer { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("what is your name"); String name = scan.nextLine(); System.out.println("what is your religion"); String religion = scan.nextLine (); if (religion .equals ("Muslim")) { System.out.println("which Mosque do you go to"); } else { System.out.println("which Church do you go to"); } String worship = scan.nextLine(); System.out.println("Your name is "+ name); System.out.println("Your religion is "+ religion); System.out.println("You worship at "+ worship); } }
13th Aug 2022, 9:02 AM
jurise mboumene
jurise mboumene - avatar
0
I want to make the worship in two words
13th Aug 2022, 9:32 AM
Adebayo Abdul Salam
Adebayo Abdul Salam - avatar
0
next() method accept single word and input pointer stays in same line after reading input. nextLine() accept entire line of input (any number of words), until new line character feed. so goes to next line after reading..
13th Aug 2022, 2:34 PM
Jayakrishna 🇮🇳