whats wrong with my code | SoloLearn: Learn to code for FREE!

+1

whats wrong with my code

import java.util.Scanner; public class StudentModule{ public static void main (String[]args){ Scanner input=new Scanner(System.in); String module; System.out.print ("What module you take?: "); module=input.next(); if (module2) System.out.print("The student taking COMPUTER SCIENCE subject"); } }

2/28/2021 10:32:45 AM

Iman Qasrina

12 Answers

New Answer

+2

In your code, you have an if statement checking if a variable 'module2' is true. If so, then you'll print a certain line of a output. But, where's your variable 'module2' ?

+2

If you're checking to see if the user typed in "module2" for their answer, then your if statement should look like this If (module == "module2") { System.out.println("The student taking COMPUTER SCIENCE subject"); } Hopefully this helps :)

+1

so in this case my variable should be module2 only?

+1

Iman Qasrina There is no variable of type boolean named 'module2' in your code. Are you sure you posted the question correctly? As far as i can see, there is only one variable module which is of type string, i.e. it stores the input from the user as a string. So obviously you can't use it in an if statement. I recommend you to go have a look at the conditional statements lesson once again

+1

im not sure😰but this is the question i get If a student is in module2 group,display message “The student is taking Computer Science subject”

+1

Can you share the question that you got? It'd be easier to help you that way..

+1

Iman Qasrina Are you sure that's the full question because that makes no sense. What is the module2 group? A data structure or do you need to check for some conditions to find out?

0

and yeah i got that error but dont know how to fix ;-;

0

this is the question i get If a student is in module2 group,display message “The student is taking Computer Science subject”

0

thats the exact question i get but sorry for the confusion..so in my school there are 3 module can be choose by student module 1 for biology coarse , module 2 for sc comp coarse and modul 3 chemistry coarse..so the situation just like that

0

and there goes the question

0

Puffy Hi :) In Java Strings, the == operator is used to check the reference of both the string objects and equals() method used to check the value equality of both strings. == – checks reference equality equals() – checks the value equality When we assign a string value to the string variable, the JVM will check if the string with the equal value already present in the string pool or not. If it is not present in the string pool, it will be added to the constant pool and the reference to that string object is returned. If it is present in the string pool, the reference to the memory address of that string object is returned. If we are assigning the equal value to another string variable, the JVM checks if the string with that value is present in the string constant pool or not. Since the string object with that value is already created in the previous step, another string variable starts referring to the previously created string object instance.