| | |
javaAddict , I have a compiling error
![]() |
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
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
}
}
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.
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
0
#2 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
}
}
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.
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:
Only one pair of 'ifs'.
This is the original question:
I also mentioned this in the other thread:
I hope I am not expected to provide online courses as how to write an if statement:
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:
Java Syntax (Toggle Plain Text)
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:
Java Syntax (Toggle Plain Text)
if (i>0) { System.out.println("i is greater than 0"); } else { System.out.println("i is lower or equal to 0"); }
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
![]() |
Other Threads in the Java Forum
- Previous Thread: Java Node to int
- Next Thread: I have given up..and need help
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php print problem program programming project recursion repositories scanner scrollbar server set size sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows






