| | |
How can I declare two variable?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#11 Oct 29th, 2009
•
•
•
•
Your question doesn't make sense.
Java Syntax (Toggle Plain Text)
int distance = 80 * time; // or int rate = 80; int time = ...; int distance = rate * time;
Thank you for helping me, next time I will try to make things clear so you can be help me again.
Cheerz MJ
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#12 Oct 30th, 2009
Hi JavaAddict
I came acrose this indent and have some question for you no. there's "X" that i don't understant where it came from?
Thank you very much for helping me.
/** Produces a multiplication table using a for loop and -10 - 10 with long.
Des, 10th November 2000.
*/
import javax.swing.JOptionPane;
public class Indent
{
public static void main(String [] args)
{
String longString;
long num = 0, result = 0;
int loops = 0;
longString = JOptionPane.showInputDialog
("Please enter a number in range +-10");
num = Long.parseLong(longString);
if ((num >= -10) && (num <= 10))
{
for (loops = 1; loops <= 10; loops++)
{
result = num * loops;
System.out.println("Row
number " + loops + " " + loops + " x " + num + " = " + result);
}
}
else
{
System.out.println("Your input number " + num + " is outside the range -10 to 10 inclusive.");
}
System.exit(0);
}
}
I came acrose this indent and have some question for you no. there's "X" that i don't understant where it came from?
Thank you very much for helping me.
/** Produces a multiplication table using a for loop and -10 - 10 with long.
Des, 10th November 2000.
*/
import javax.swing.JOptionPane;
public class Indent
{
public static void main(String [] args)
{
String longString;
long num = 0, result = 0;
int loops = 0;
longString = JOptionPane.showInputDialog
("Please enter a number in range +-10");
num = Long.parseLong(longString);
if ((num >= -10) && (num <= 10))
{
for (loops = 1; loops <= 10; loops++)
{
result = num * loops;
System.out.println("Row
number " + loops + " " + loops + " x " + num + " = " + result);
}
}
else
{
System.out.println("Your input number " + num + " is outside the range -10 to 10 inclusive.");
}
System.exit(0);
}
}
Last edited by M.Jama; Oct 30th, 2009 at 1:05 pm.
0
#13 Oct 30th, 2009
What do you mean by "X".
Maybe this:
Maybe this:
number " + loops + " " + loops + " x " + num + " = " + result); Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#14 Oct 30th, 2009
•
•
•
•
What do you mean by "X".
Maybe this:
number " + loops + " " + loops + " x " + num + " = " + result);
number " + loops + " " + loops + " x " + num + " = " + result);
I have practised while, for and do and their conditions but this one I have met X!!
why it's there if it's not declared anywhere?
Thanks
MJ
0
#15 Oct 31st, 2009
The ones between the "" are strings and they will be printed they way they are. Surely you have written the Hello World program:
The loops, num ,results are variables. Did you try to run it and see what it prints?
System.out.println("Hello World"); System.out.println("Row number " + loops + " " + loops + " x " + num + " = " + result);
The loops, num ,results are variables. Did you try to run it and see what it prints?
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#16 Oct 31st, 2009
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
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
Last edited by M.Jama; Oct 31st, 2009 at 7:00 am.
0
#17 Oct 31st, 2009
You know very well that this is not the way to declare variables:
If you can't fix this, don't go any further.
This is how you read a number
Do the same for the second number.
Use if statements to check the numbers:
If you don't know cards then:
1: Ace
2: two
....
11: Jack
12: Queen
13: King
As for the colors:
Hearts, Spade, ... and I don't know the english names of the rest
You can do any type of mapping for those.
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
Java Syntax (Toggle Plain Text)
int firstnumber = 1,2,3,4,5,6,7,8,9,10,11,12,13; int secondnumber = 1,2,3,4;
This is how you read a number
Java Syntax (Toggle Plain Text)
System.out.println("Enter firstnum: "); int fnum = QueenOfDaimond .nextInt(); System.out.println("Firstnum: "+fnum);
Use if statements to check the numbers:
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 }
If you don't know cards then:
1: Ace
2: two
....
11: Jack
12: Queen
13: King
As for the colors:
Hearts, Spade, ... and I don't know the english names of the rest
You can do any type of mapping for those.
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
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
-2
#19 Oct 31st, 2009
First of all...Keep in mind...What do u want to do and display in window...
Because u have two varibles initialized with zero
then totalfeet= inches*12;
It means totalfeet=0*12;
which results total feet=0
And u r not displaying totalfeet
You are displayig 5*12=60
...
Put up correct question..so that we can help u
Because u have two varibles initialized with zero
then totalfeet= inches*12;
It means totalfeet=0*12;
which results total feet=0
And u r not displaying totalfeet
You are displayig 5*12=60
...
Put up correct question..so that we can help u
0
#20 Oct 31st, 2009
•
•
•
•
First of all...Keep in mind...What do u want to do and display in window...
Because u have two varibles initialized with zero
then totalfeet= inches*12;
It means totalfeet=0*12;
which results total feet=0
And u r not displaying totalfeet
You are displayig 5*12=60
...
Put up correct question..so that we can help u
This thread has 19 posts and you went and read only the first and skipped the rest?
Like I said, if you read the rest of the thread you will realize that your answer has nothing to do with the rest of the questions asked.
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- declare variable to open file (C++)
- Variable use from any form (Visual Basic 4 / 5 / 6)
- How to access a private variable (C++)
- Setting variable within an exec (@sql) (MS SQL)
- send email Undefined variable: (PHP)
- How can I declare this? (VB.NET)
- declaring a Date variable (Java)
- volatile variable (Perl)
- C--Structures(inside structure declaration of variable of same type is not allowed) (C)
- Textbox always display a variable (C#)
Other Threads in the Java Forum
- Previous Thread: Need Additional Code
- Next Thread: Getting an error I do not understand!! (student)
Views: 595 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component consumer database desktop detection draw eclipse encode error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number object online oracle os print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner score screen server set size sms socket sort sql string swing template test threads time transfer tree update windows working xstream






