Java : max of 2 integers
abdelmalek@bennour
Posted messages
18
Status
Membre
-
neogenesis Posted messages 5303 Status Contributeur -
neogenesis Posted messages 5303 Status Contributeur -
Hello,
I am a beginner in Java, with Java 1.5.9
I want to create a small program that gives the max between two integers: as follows
public class Max //max between two integers
{
public static void main(String args[])
{
int nb1, nb2;
nb1 = Keyboard.readInt("Enter an integer:");
nb2 = Keyboard.readInt("Enter an integer:");
if (nb1 > nb2)
System.out.println("the largest integer is " + nb1);
else
System.out.println("the largest integer is " + nb2);
}
}
Java reports an error at 'k' (Keyboard) and the dot before println
How can I fix the error, thank you.
I am a beginner in Java, with Java 1.5.9
I want to create a small program that gives the max between two integers: as follows
public class Max //max between two integers
{
public static void main(String args[])
{
int nb1, nb2;
nb1 = Keyboard.readInt("Enter an integer:");
nb2 = Keyboard.readInt("Enter an integer:");
if (nb1 > nb2)
System.out.println("the largest integer is " + nb1);
else
System.out.println("the largest integer is " + nb2);
}
}
Java reports an error at 'k' (Keyboard) and the dot before println
How can I fix the error, thank you.
Configuration: Windows XP Firefox 3.0.4
6 réponses
Hello,
Where is your keyboard from? Did you declare it somewhere?
--
Google is your friend, think about it before posting!
Where is your keyboard from? Did you declare it somewhere?
--
Google is your friend, think about it before posting!
Use the Scanner class instead, it's cleaner (for me)
import java.util.Scanner; (note this at the beginning of the class)
Then in your main
Scanner keyb = new Scanner(System.in);
Then in your program when you want to read keyboard input you do a:
Integers: keyb.nextInt();
--
Google is your friend, think about it before posting!
import java.util.Scanner; (note this at the beginning of the class)
Then in your main
Scanner keyb = new Scanner(System.in);
Then in your program when you want to read keyboard input you do a:
Integers: keyb.nextInt();
--
Google is your friend, think about it before posting!
I am really sorry, because I tried to trigger a new message in the forum while I was responding to you
your response is wonderful, thank you my brother it works very, very well for the first problem
now we still need to address the second error case: the error signal at the point before println
forgive me once again, thank you
your response is wonderful, thank you my brother it works very, very well for the first problem
now we still need to address the second error case: the error signal at the point before println
forgive me once again, thank you
but I do not want to concatenate
the problem is in the instruction: System.out.println("the largest integer is ", nb2); Java reports the error at the second point
the problem is in the instruction: System.out.println("the largest integer is ", nb2); Java reports the error at the second point
Yes, I understand now
instead of writing: System.out.println("the largest integer is ", nb2);
we write: System.out.println("the largest integer is " + nb2); it’s not like the Pascal language
is the program now running correctly
thank you again my brother, it really means a lot
instead of writing: System.out.println("the largest integer is ", nb2);
we write: System.out.println("the largest integer is " + nb2); it’s not like the Pascal language
is the program now running correctly
thank you again my brother, it really means a lot
Indeed, Pascal and Java are similar but different :-)
Here’s a good site to start with Java:
https://openclassrooms.com/fr/courses/6173501-debutez-la-programmation-avec-java?archived-source=26832
Have a good evening, and remember to mark your status as resolved before I take care of it :-)
See you later
--
Google is your friend, keep that in mind before posting!
Here’s a good site to start with Java:
https://openclassrooms.com/fr/courses/6173501-debutez-la-programmation-avec-java?archived-source=26832
Have a good evening, and remember to mark your status as resolved before I take care of it :-)
See you later
--
Google is your friend, keep that in mind before posting!