Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can you tell me where the errors are in these lines of code?
Java
System.out.println ("Enter the Mobile Brand name");

mbBrand keyboard.nextLine);
System.out.println("Enter the price");
price = keyboard.nextInt ();
mbBrand. toLowercase();

This is the entire code I have if it helps

Java
import java.util.Scanner;

public class CompErrors {

public static void main(String[] args);


Scanner keyboard = new Scanner (System. in);

string mbBrand;

double price;

double System.out.println ("Enter the Mobile Brand name");
mbBrand keyboard.nextLine);
System.out.println("Enter the price");
price = keyboard.nextInt ();
mbBrand. toLowercase();


What I have tried:

I have been at it for a few hours trying to find out where the errors are in these lines of code. I am a bit of a newbie so I may be missing something fairly obvious.
Posted
Updated 12-Feb-21 18:33pm
v2

Okay so I was playing around with it and immediately got what you guys responded with but there’s one error left here. I’m not sure if I improved it or made it worse. Any input would help!

mbBrand ; (1 error here. Says <identifier> expected)
I believe it’s because my curly brackets are misplaced. But I’m still not quite sure. If you could aid me with this id be grateful!


This is my full edited code.




import java.util.Scanner;

public class CompErrors {

public static void main(String[] args);

Scanner keyboard = new Scanner (System. in);

double string;


   mbBrand ; (1 error here. Says <identifier> expected)


double price; {

System.out.println("Enter the Mobile Brand name");
mbBrand = keyboard.nextLine();
System.out.println("Enter the price");
price = keyboard.nextInt ();
mbBrand. toLowercase();

}
        }
 
Share this answer
 
v2
Comments
Richard MacCutchan 13-Feb-21 4:35am    
You have declared a variable named string as a double type, which is a really bad idea; use meaningful names for variables. The next line contains a word that the compiler does not understand. What do you think it is supposed to do? You have an opening brace at the end of the next line which has no purpose or meaning. You have declared price as a double type, but then you call nextInt (which returns an integer) to assign it a value. Finally you once again call toLowercase on a variable but ignore the returned value.

To be honest this looks like it is written by someone who has not learned even the basics of the language. I suggest you go to The Java™ Tutorials[^] and do some studying.
Programnewbie 13-Feb-21 20:34pm    
To be honest it’s only been a few weeks since I’ve been trying to teach the basics of programming to myself. I’ve gotten some practice code projects from the web and acquired a used text which I’ve been trying to understand. Seems I may need to read up on the tutorial as you suggested. Any tips on how this code would be properly written out? The source where I got it from doesn’t have a completed form of this problem. I want to see how this one is properly done and go over the basics once again. It seems I need to teach myself the basics once more and possibly apply to a college class to learn more!
Richard MacCutchan 14-Feb-21 5:09am    
Teaching yourself is not easy, especially as so much that can be found on the internet is badly written, or sometimes just wrong. If you can find a good college course then that would be the ideal choice, as you get proper tuition, and feedback. If that is not available then the official tutorials are a reasonable second choice. Use the link I gave you above and follow them from the very beginning to get a good understanding. Try all the exercises (even the simple ones) in order to get the concepts and rules fixed in your mind. I was a reasonably experienced C/C++ programmer when I first learned Java, and I did it from these tutorials myself.
Your code is incomplete, so it will not even compile. Also in addition to what OriginalGriff posted the line:
Java
mbBrand. toLowercase();

will not do what you think. See String (Java SE 11 & JDK 11 )[^].
 
Share this answer
 
This line:
mbBrand keyboard.nextLine);
is completely meaningless.
The bracket isn't matching anything, mbBrand is a string so it's just "sitting there" all on it's own, keyboard.nextLine is a method.

Probably what you meant was:
mbBrand = keyboard.nextLine();

And there is a good chance that fixing that with fix your other errors.

But if you have been staring at that for "a few hours" trying to fix it, then you probably need to re-read your course materials from the beginning a few times before you go any further!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900