Hi there,
This afternoon, i have been studying how to read numbers using Scanner as you adviced me. However here I need some help because I can compile it:

merci beaucoup.

import java.util.Scanner;

public class Exercise19
 {  
   public static void main(String [] args){ 
       Scanner QueenOfDaimond = new Scanner(System.in);


       System.out.println("Enter firstnum: ");
       int fnum = QueenOfDaimond .nextInt();
       System.out.println("Firstnum: "+fnum);

       Scanner AceOfDiamonds = new Scanner(System.in);

           System.out.println("Enter secondnum: ");
           int snum = AceOfDiamonds .nextInt();
           System.out.println("Secondnum: "+snum);
   }


             if (fnum is in range) { 
         if (second num is in range) {  
            // calculate the ouput 
          } else {    
           // print second num not in range    }
       } else {
        // print fnum is not in range}if (fnum is in range) {

              if (second num is in range) {
                  // calculate the ouput
               } else {
                   // print second num not in range
               }
           } else {
            // print fnum is not in range
           }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Comments
You been asked to use code tags few times and you ignored it. That is bad...

One, code tags. Use them.

Two, Where's the error and what is it? Point out a line number.

Three, is this pseudo-code or real code? Pseudo-code doesn't compile and you shouldn't try to compile it. You have to use the syntax of JAVA for it to compile:

if (fnum is in range[B])[/B]

If javaAddict gave you this is another thread, he didn't intend for you to try to compile it. He's telling you what to do in English as a nudge in the right direction. You still need to convert it to Java.

Four, and most important, don't start a new thread stating the name of the person who you want to have help you. Maybe javaAddict is busy. He helped you last time. That doesn't mean he has time to help you this time, will choose to help you this time, or has the answer (he obviously would know what was wrong with THIS code). Specifying who you expect to help you in advance defeats the whole purpose of the forum. Plus it's a bit demanding. Plus it tells everyone else not to bother answering.

Edited 3 Years Ago by happygeek: fixed formatting

First of all you don't need to have 2 Scanner classes. One would be enough and you can call its methods as many times as you like in order to read as much input as you want.


And to VernonDozier,

the thread is this:
http://www.daniweb.com/forums/thread234373.html
Check posts numbers 16, 17.

The code I gave was this:

if (fnum is in range) {
  if (second num is in range) {
     // calculate the ouput
   } else {
     // print second num not in range }
} else {
      // print fnum is not in range
}

Only one pair of 'ifs'.

This is the original question:

JavaAddict,
Thanks, I see I what I have missed. Btw. I was trying to workout some random online exercises about the scanner, I have done some easy one except this one:
Write a program to input two numbers using Scanner class, the first number in the range 1 to 13 and the second number in the range 1 to 4. When the numbers are entered check that they are in the correct range. If not issue an error message using println().
Output the card face (or type) for the first number and the suite for the second number.
Your output should have a message such as “Queen of Diamonds” for the input of 12 and 2. The Ace of Diamonds would be 1 and 2; the Ace of Clubs would be 1 and 1.
Hint use two switch statements and the order of suites is Clubs, Diamonds, Hearts and Spades.

I could do only:

import java.util.Scanner;

public class Scanner{

public static void main(String [] args){
Scanner QueenOfDaimond = new Scanner(System.in);

int firstnumber = 1,2,3,4,5,6,7,8,9,10,11,12,13;
int secondnumber = 1,2,3,4;


System.out.println("Enter firstnum: ");
fnum = QueenOfDaimond .nextInt();
System.out.println("Enter secondnum: ");

}
}
Can you explain me how to built things like that?
I cannot thank you enough its very kind of you to teach me a lot.
MJ

I also mentioned this in the other thread:

As for the if and switch statements, that is up to you.
You should know how to write a simple if statements or how to use the '>' or the '<' operator, as well as the '&&' and the '||'.
If not, I can not teach you these thinks, you need to study for yourself.

Also search for the sun tutorials to find how to work on a switch. You should be able to find an example

I hope I am not expected to provide online courses as how to write an if statement:

if (i>0) {
   System.out.println("i is greater than 0");
} else {
   System.out.println("i is lower or equal to 0");
}

Edited 7 Years Ago by javaAddict: n/a

This article has been dead for over six months. Start a new discussion instead.