Jump to content

debug for java problem please!

buklu

You have not declared 'num' and 'answer', so Java doesn't know them (or know what to do with them).

 

Declare them as an int and String respectively above.

 

(Also, in the future just look at the red underline and see what the error is)

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Minibois said:

You have not declared 'num' and 'answer', so Java doesn't know them (or know what to do with them).

 

Declare them as an int and String respectively above.

 

(Also, in the future just look at the red underline and see what the error is)

correct.PNG.603e7aa9b6cc4a37749e54f9373c6945.PNG

rock the world

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 more small things you should close the Scanner (input.close();) and rename your class Test or some other more meaningful name, Classes always start with an Uppercase letter. Also its no necessity but in general its better practice to use {} brackets even if your if statement does only one instruction and therefore you don`t need, you should use them anyway.

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, Klemmbrett said:

3 more small things you should close the Scanner (input.close();) and rename your class Test or some other more meaningful name, Classes always start with an Uppercase letter. Also its no necessity but in general its better practice to use {} brackets even if your if statement does only one instruction and therefore you don`t need, you should use them anyway.

how do i rename test to Test?thanks

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Canada EH said:

What is the problem at hand?

hint.PNG.aab08ab875df2e4db429b60b6c7678f4.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

result.PNG.f7b2d3ceb32b7b8d03666455e7ca71f1.PNG

7 minutes ago, Canada EH said:

What is the problem at hand?

hint.PNG.aab08ab875df2e4db429b60b6c7678f4.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

You are assigning a value to 'larger'.

This statement is asking "is num1 bigger than num2?", if so: 'larger' will now hold the value of num1. Otherwise; the value of 'larger' is now num2.

 

https://en.wikipedia.org/wiki/%3F:#Java

It's kind of like an 'if statement' in 1 line.

 

So this statement will check the value of num1 and num2 and whichever is higher in value, will be assigned to 'larger'.

You could reverse the "bigger than" carrot thingy and call the 'larger' vairable now 'smaller' and it will now assign the smaller value to that variable.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

( num1 > num2) ? 

if num1 is greater than num2

num1 : num2;

then larger equals nium1 else larger equals num2

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to comment
Share on other sites

Link to post
Share on other sites

46 minutes ago, Minibois said:

You are assigning a value to 'larger'.

This statement is asking "is num1 bigger than num2?", if so: 'larger' will now hold the value of num1. Otherwise; the value of 'larger' is now num2.

 

https://en.wikipedia.org/wiki/%3F:#Java

It's kind of like an 'if statement' in 1 line.

 

So this statement will check the value of num1 and num2 and whichever is higher in value, will be assigned to 'larger'.

You could reverse the "bigger than" carrot thingy and call the 'larger' vairable now 'smaller' and it will now assign the smaller value to that variable.

can you help me

Q1.PNG.88a4700fad866fdbc407a5c56720a963.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, camjocotem said:

@buklu Just a helpful tip, for questions like these you'll ideally wanna put them in Software > Programming

:)

hello

Q1.PNG.2e753858f6d1e1e270bfd46a5e11e7f1.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, buklu said:

can you help me

 

As it says in the error message; you can't place an int into a String variable.

an int a number (without decimals) and a String is text. Either change the 'larger' variable to an int, or convert your result to a string: http://javadevnotes.com/java-integer-to-string-examples

If you choose to take the 'making 'larger' an int' route, you will have to change the 'System.out.print' line to this:

//You can't just 'print' an int. Place the double quotes before the int variable will make the code understand you have to print it as a string
System.out.print(""+larger);

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, Minibois said:

As it says in the error message; you can't place an int into a String variable.

an int a number (without decimals) and a String is text. Either change the 'larger' variable to an int, or convert your result to a string: http://javadevnotes.com/java-integer-to-string-examples

If you choose to take the 'making 'larger' an int' route, you will have to change the 'System.out.print' line to this:


//You can't just 'print' an int. Place the double quotes before the int variable will make the code understand you have to print it as a string
System.out.print(""+larger);

 

correct1.PNG.aba39690c6e66cc302124b9306f415b8.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, buklu said:

 

Please stop posting screenshots of your code with no context, just ask what you are not understanding; it makes giving the advice much easier.

As  I said, either make the 'larger' variable an int or convert the int you want to place inside 'larger' to a String. Either or.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/25/2018 at 7:38 PM, Minibois said:

Please stop posting screenshots of your code with no context, just ask what you are not understanding; it makes giving the advice much easier.

As  I said, either make the 'larger' variable an int or convert the int you want to place inside 'larger' to a String. Either or.

varia.PNG.8d2aa2c2ea46ccde915a79a9a4355a16.PNG

thank you

Link to comment
Share on other sites

Link to post
Share on other sites

43 minutes ago, buklu said:

 

thank you

You have not declared 'grade'. 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

19 hours ago, Minibois said:

You have not declared 'grade'. 

declare grade as char,what is the statement?please

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, buklu said:

declare grade as char,what is the statement?please

https://www.tutorialspoint.com/java/java_characters.htm

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×