#comparison yields wrong output
1 messages ยท Page 1 of 1 (latest)
the 3 pictures i have sent on my issues that are coming out
could u please give a quick explanation of the task and guide us through ur code? also please post the code as formatted code block with syntax highlighting and elaborate on what's unclear to u in particular
yes
i can send you the code
import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
System.out.println("Enter two positive integers, the first smaller than the second.");
do {
System.out.print("First: ");
a = in.nextInt();
System.out.print("Second: ");
b = in.nextInt();
if (a >= b) {
System.out.println("Invalid input. The first number must be smaller than the second. Please try again.");
}
} while (a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
comparison yields wrong output
Changed the title to comparison yields wrong output.
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
oh
- could u please give a quick explanation of the task
- and guide us through ur code?
- also please post the code as formatted code block with syntax highlighting
- and elaborate on what's unclear to u in particular
u have a tendency to only read half of whats been asked
once u addresses all 4 items, people will be able to help u ๐
import java.util.Scanner;
public class TwoNumbers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
int b;
boolean validInput = false; // This boolean variable is used to control the loop
while (!validInput) {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
System.out.print("Second: ");
b = in.nextInt();
validInput = (a < b); // Check if the first number is smaller than the second
if (!validInput) {
System.out.println("Invalid input. The first number must be smaller than the second. Please try again.");
}
}
System.out.println("You entered " + a + " and " + b);
}
}
code issues
i am looking at where i did wrong
i am not now sure what i did wrong
it wants a code
The Scanner class is used to take input from the user.
Two integer variables a and b are declared to store the user's input.
The boolean variable validInput is initialized to false to control the loop.
The do-while loop continues until validInput becomes true.
Inside the loop, the user is prompted to enter two positive integers with specific messages for "First:" and "Second:".
The validInput is set to true if the condition (a < b) is satisfied, meaning the first number is smaller than the second.
If the input is not valid, an error message is displayed, and the loop continues.
Once a valid input is provided, the loop exits, and the entered values are displayed.
Regarding the error:
The error you encountered (variable a might not have been initialized and variable b might not have been initialized) occurs because the compiler cannot guarantee that variables a and b have been assigned values before their use in the System.out.println statement. To resolve this, you can either initialize a and b with default values when declaring them or use a do-while loop instead of a while loop to ensure they are assigned values within the loop.
that sounds like u asked chatgpt to solve ur issue and explain ur code
yeah but i still don't get it
- could u please give a quick explanation of the task
- and guide us through ur code?
- also please post the code as formatted code block with syntax highlighting
- and elaborate on what's unclear to u in particular
once u did that, we will help u
About the Error:
The computer sometimes gets worried that we are using the numbers a and b in the last sentence before the person has even given us any numbers. We need to convince the computer that we will only use a and b after we are sure the person has given us the right kind of numbers. We do this by using a special loop called do-while.
ill just stop responding until u did all 4 things now.
and use your own words , not some copy paste from the assignment
We use a special tool called Scanner to talk to the person using our program.
We have two boxes (a and b) to keep the numbers that the person types.
We also have a special switch (validInput) that helps us decide if the numbers are correct or not.
We use a special loop called do-while to keep asking for numbers until they give us the right ones.
Inside the loop, we ask for the first number, then the second number.
We check if the first number is smaller than the second. If it is, we say everything is good by turning on the validInput switch.
If the numbers are not right, we say that and keep asking again.
Once the person finally gives us the right numbers, we exit the loop and tell them what they entered.
who are you again? hi
i have anwered 4
of ur questions
u did not.
i did look at it. I'm reading all ur messages
i know. that's why im offering u my help. after u did the 4 steps
u did none of them so far
cause your very unclear and your refusing to actually read anything. Even your own error screen which has the actual solution
i will answer it again
that's one of the most ridiculous asking for help i've ever seen
desbribe the problem with your own words, so that you can also understand it and paste a FORMATTED code, not just pasted in plain text because it looks like shit
i get ur frustration, but please remain friendly. also acknowledge a certain language barrier here
thanks
i wrote everything man
people that just texted are rude
lets do it together, step by step
yes
step one, please explain me what ur task is about
ok
the task i need a code for this
what is "this"?
does ur code have to compute a + b?
yes
so ur supposed to add two numbers together?
when i runed it it gave me an error
or multiply them?
boolean validInput = false;
while (!validInput) {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
System.out.print("Second: ");
b = in.nextInt();
validInput = (a < b);
if (!validInput) {
System.out.println("Invalid input. The first number must be smaller than the second. Please try again.");
}
}
this is what i wrote just now
for that
that code doesn't add two numbers together
u just said ur supposed to add two numbers. ur code doesn't add two numbers at all
could u please stop doing random stuff
stick with me
ok ok sorry
read what i say, respond to what i say
yeah
i am sorry
are u sure u have to add two numbers?
Complete this program, prompting the user to enter two positive numbers a and b so that a is less than b.
i know, i can read that myself
i feel like u don't understand the task. so ur not supposed to add two numbers together at all
i have make it less then b
yeah
anyways. next step. please post ur code as formatted text with syntax highlighting
heres how to do it :
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
what's unclear to u
i can't help u if all u say is "im confused"
confused on what exactly?
what can i explain in more detail to help u?
๐
what do u not understand about the last thing ?
The error message you are seeing is because the variables a and b might not have been initialized before they are used in the System.out.println statement. This error occurs when we declare a variable without initializing it
the last thing Zabuzard asked from u. Please try to respond to the questions and not do random things
my question is from only from me to you why you blocked me
It might feel weird, but its yourself that it blocking yourself from getting help, if u can be clear and try to respond in normal matter, this issue could of been solved more then an hour ago
you are also a bot
pfft
please post ur code as formatted text with syntax highlighting
ive explained how to do it here:
#1195379743013482626 message
i am looking at it
i'm not a bot, i just do not respond well to the things u said on your other topic ...
well. if u continue behaving like this, u will be kicked out and not get help at all
is that really what u want?
// Example java program
int value = 5;
System.out.println(value); idk where this goes
please just answer like Zabuzard requested
well they blocked me for no reason
and i wanted to know why
thats all
they don't have to be rude
Because you're making it very hard to help you
the reason is clearly u being unfriendly to people trying to help u in their free time
i am looking at it
just wrap your code in a code block as requested
thats not an answer
nah he was rather very rude in his other topic so. Well ...
oh ok
you and i just met
people can block u as they want. especially if they see u being rude to someone else
it is very much an answer. People here try to help those they can, and help us help them. But in case someone is rude, and just stubbornly refusing helping hands/requests...
that's the reason. My choice to block, your choice to respond like that. Things will happen that u do not like
also doesnt mean that your blocked that i'm not reading your messeges...
she is starting problems bro @night gull
can you remove her i want to forcus on my code error please
u asked why they blocked u and they responded
yes
but i get that u want to get back on the problem. so let's do that
please post ur code as formatted text with syntax highlighting
ive explained how to do it here:
#1195379743013482626 message
import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
} @golden bane
@night gull import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
how
do i use the bot
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
opriate prompt for the user to enter the first number
System.out.print("Enter the first number: ");
a = in.nextInt();
// HINT: Choose an appropriate prompt for the user to enter the second number
System.out.print("Enter the second number: ");
b = in.nextInt();
// Calculate and print the sum of the two numbers
int sum = a + b;
System.out.println("The sum of " + a + " and " + b + " is " + sum);
// Calculate and print the difference of the two numbers
int difference = a - b;
System.out.println("The difference between " + a + " and " + b + " is " + difference);
// Calculate and print the product of the two numbers
int product = a * b;
System.out.println("The product of " + a + " and " + b + " is " + product);
// Calculate and print the quotient of dividing the first number by the second number
double quotient = (double) a / b;
System.out.println("The quotient of dividing " + a + " by " + b + " is " + quotient);
}
}
i got it
nope
thanks
huh?
?
d: ");
int num1 = input.nextInt();
int num2 = input.nextInt();
while (num1 >= num2) {
System.out.println("The first number must be smaller than the second number. Please try again.");
System.out.println("Enter two positive integers, the first smaller than the second: ");
num1 = input.nextInt();
num2 = input.nextInt();
}
// Rest of the code goes here
}
im not sure what ur trying to tell me with that
i still need help
please read what the bot says...
i was trying the bot out
then please post the code proper
it really isn't that hard
please post ur code as formatted text with syntax highlighting
ive explained how to do it here:
#1195379743013482626 message
yes
three backticks, java, newline, code, newline, three backticks
Paste your code between three backticks
Two blocks of triple backticks
And your code between them
would the backtick actually be on other language's keyboard ?
yes
i read this
Of course! I'll do my best to assist you. Could you please provide more details about the error you are experiencing? Additionally, if you can share the code or the specific error message, it would be helpful in understanding the issue and providing a solution.
yes
and worst case you copy/paste or remap. I mean my current keyboard has a broken T key ๐
please stop using the chatgpt command. it won't help u here
it only interrupts our conversation
import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a = 0;
int b = 0;
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
no
๐ญ
solving ur issue, if u would be cooperative, stick with us and not constantly get sidetracked, would be solved within 5-10mins
ok
๐
Repeat after me okay?
?
Why cant u Just answer a question? I want to help you
repeat what ?
ok
i wrote the code tho
Copy and paste it into your message box on discord
Okay
You are clearly trolling sorry
That's unbelieveable
i am not trolling
<@&272766283597217802> this is...
Do you know how to write a message on discord Channel?
Answer me
answer what
Do you know how to write a message on discord Channel?
yes i do
So write a message I asked for
It's not hard to do:
please remain friendly. if u don't want to help anymore, bc its unpleasant, just leave the discussion or block the user. better than being mad at them. someone else might have the patience to assist. thanks
i did that
Copy this sign
it won't let me enter on my computer
when i wrote what u said
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
// Clear the buffer
in.nextLine();
System.out.print("Second: ");
b = in.nextInt();
if (a <= 0 || b <= 0 || a >= b) {
System.out.println("Invalid input. Please try again.");
}
} while (a <= 0 || b <= 0 || a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
} ```java
asci code = 96
ok
Paste your code below the three ticks and Java Word
And below your code paste three ticks Without Java Word
do it like what I showed in my image
there
java import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
// Clear the buffer
in.nextLine();
System.out.print("Second: ");
b = in.nextInt();
if (a <= 0 || b <= 0 || a >= b) {
System.out.println("Invalid input. Please try again.");
}
} while (a <= 0 || b <= 0 || a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
Ok sorry, but I cannot help you
that's fair, thank you for trying. highly appreciated 
i did this
like what he told me too do
do it like in this image please
perhaps we have regained our patience batteries by tomorrow ๐
i did
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
// Clear the buffer
in.nextLine();
System.out.print("Second: ");
b = in.nextInt();
if (a <= 0 || b <= 0 || a >= b) {
System.out.println("Invalid input. Please try again.");
}
} while (a <= 0 || b <= 0 || a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
} ```java
yeah
if u cannot type ` , the shortcut is alt+096
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
// Clear the buffer
in.nextLine();
System.out.print("Second: ");
b = in.nextInt();
if (a <= 0 || b <= 0 || a >= b) {
System.out.println("Invalid input. Please try again.");
}
} while (a <= 0 || b <= 0 || a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
} ```java
Detected code, here are some useful tools:
javaimport java.util.Scanner;
public class TwoNumbers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
// Clear the buffer
in.nextLine();
System.out.print("Second: ");
b = in.nextInt();
if (a <= 0 || b <= 0 || a >= b) {
System.out.println("Invalid input. Please try again.");
}
}
while (a <= 0 || b <= 0 || a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
if u type the last image as text in here it should appear as code and then all u have to do is insert the proper code
might i infom what your language is?
english
right , then its not some auto translate problem
nope
can u insert your code formatted in the correct way please
i understand you
i did that
like others have said, the issue is resolved in less then a minute if u take the time to paste it properly
scroll up
test
if u tried the image like i've shown u would have made a code block
then all u had to do was replace the test with the actual code
so its 3 tiks and test?
Please use this format for posting code:
```java
// Example java program
int value = 5;
System.out.println(value);
```
Which results in:
// Example java program
int value = 5;
System.out.println(value);
For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.
that ^
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
} ```
Detected code, here are some useful tools:
javaimport java.util.Scanner;
public class TwoNumbers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
int b;
// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
place the import on a new line
oh ok
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */ ```
Detected code, here are some useful tools:
java// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
๐
ok
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */ ```
Detected code, here are some useful tools:
java// HINT: Choose an appropriate loop and a loop condition
/* Your code goes here */
{
System.out.println(
"Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} /* Your code goes here */
right, before this is getting to silly. Do u see the a and b u declared ?
int a;
int b;
those
do u see them ?
yes
ok, the problem is that u did not initialize them, hence they cannot be used
so u need to place a default value in them to be initialized
yeah ik
that's your problem.
it even sais so on the actual error messege, so it's always wise to read those
iok
import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
a = in.nextInt();
System.out.println("First: " + a);
b = in.nextInt();
System.out.println("Second: " + b);
} while (a >= b);
// This line should only be printed when the input is correct
System.out.println("You entered " + a + " and " + b);
}
}
<@&272766283597217802>
i got one part correct
the other 2 are wrong
please use code blocks, and don't randomly ping moderators
and the testcases also say where the issue lies.
you do not have enough validation
please dont ping the mods unless u have sth that requires attention by a moderator, thank you
i do
i am getting errrors
please look above
what i sent
yeah, but the moderators are not there for assisting u with ur code issues
i know but
they are there for protecting u if someone is rude to u or otherwise conflicts the rules
so please dont abuse this ping
its like calling the police
yeah yeah
in fact, our telephones ring and we rush to the computer when u do that
Also this is not a code error, you're literally missing code. You haven't implemented the requested validation. CFR #rules not doing your homework for you.
i am looking at the issue
don't give me that
don't give you what?
<@&272766283597217802> this does seem an apt ping?
And you were wondering why people blocked you earlier, this seems like a good showcase.. I am trying to help, and point out where the issue lies.
if you don't want to help then go
its fine pal
@tired ingot screenshot fast; things are not written in stone on discord ๐
wow
@tired ingot i did nothing to you bro
i read the rules ok
and i am looking at the code
there isn't a problem between us
i know i am doing the work on my own
eh, he already edited it. He's seemingly just ignoring them if he actually read them. One can only lead a horse to water as the proverb goes.
you ignored me
what wrongs with don't give me that
thats not for u
i seen it
Why did I got mentionned 4 times ?
I think not you specifically, rather your purpleness
audit log exists
๐