javaAddict , I have a compiling error

Reply

Join Date: Oct 2009
Posts: 13
Reputation: M.Jama is an unknown quantity at this point 
Solved Threads: 0
M.Jama M.Jama is offline Offline
Newbie Poster

javaAddict , I have a compiling error

 
-1
  #1
31 Days Ago
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
}
}
Last edited by M.Jama; 31 Days Ago at 3:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
0
  #2
31 Days Ago
Originally Posted by M.Jama View Post
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
}
}

One, code tags. Use them.


[code]
// paste code goes here
[/code]


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)

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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,672
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 225
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is online now Online
Posting Virtuoso
 
0
  #3
31 Days Ago
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:
  1. if (fnum is in range) {
  2. if (second num is in range) {
  3. // calculate the ouput
  4. } else {
  5. // print second num not in range }
  6. } else {
  7. // print fnum is not in range
  8. }

Only one pair of 'ifs'.

This is the original question:
Originally Posted by M.Jama View Post
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:
  1. if (i>0) {
  2. System.out.println("i is greater than 0");
  3. } else {
  4. System.out.println("i is lower or equal to 0");
  5. }
Last edited by javaAddict; 31 Days Ago at 6:04 pm.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC