Java : max of 2 integers

abdelmalek@bennour Posted messages 18 Status Member -  
neogenesis Posted messages 5303 Status Contributor -
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.
Configuration: Windows XP Firefox 3.0.4

6 answers

  1. neogenesis Posted messages 5303 Status Contributor 530
     
    Hello,

    Where is your keyboard from? Did you declare it somewhere?
    --
    Google is your friend, think about it before posting!
    1
  2. abdelmalek@bennour Posted messages 18 Status Member 7
     
    I didn't quite understand, what statement do I make and how?
    0
    1. neogenesis Posted messages 5303 Status Contributor 530
       
      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!
      0
  3. abdelmalek@bennour Posted messages 18 Status Member 7
     

    Can someone help me or where can I find French documentation on all Java classes and methods?

    0
    1. neogenesis Posted messages 5303 Status Contributor 530
       
      Hey!
      If my help doesn't suit you, at least have the courtesy to tell me why...
      --
      Google is your friend, keep that in mind before posting!
      0
  4. abdelmalek@bennour Posted messages 18 Status Member 7
     
    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
    0
    1. neogenesis Posted messages 5303 Status Contributor 530
       
      Remplace la + un +
      En java pour concaténer une variable à une chaîne on utilise l'opérateur +
      --
      Google est votre ami, pensez y avant de poster !
      0
  5. abdelmalek@bennour Posted messages 18 Status Member 7
     
    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
    0
  6. abdelmalek@bennour Posted messages 18 Status Member 7
     
    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
    0