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: M.Jama is an unknown quantity at this point 
Solved Threads: 0
M.Jama M.Jama is offline Offline
Newbie Poster
 
0
  #11
Oct 29th, 2009
Originally Posted by javaAddict View Post
Your question doesn't make sense.
  1. int distance = 80 * time;
  2. // or
  3. int rate = 80;
  4. int time = ...;
  5. 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
Reply With Quote Quick reply to this message  
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
 
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);
}
}
Last edited by M.Jama; Oct 30th, 2009 at 1:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
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: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #13
Oct 30th, 2009
What do you mean by "X".
Maybe this:
number " + loops + " " + loops + " x " + num + " = " + result);
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
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
 
0
  #14
Oct 30th, 2009
Originally Posted by javaAddict View Post
What do you mean by "X".
Maybe this:
number " + loops + " " + loops + " x " + num + " = " + result);
I meant this:
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
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: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
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:
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
Reply With Quote Quick reply to this message  
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
 
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
Last edited by M.Jama; Oct 31st, 2009 at 7:00 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
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: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #17
Oct 31st, 2009
You know very well that this is not the way to declare variables:
  1. int firstnumber = 1,2,3,4,5,6,7,8,9,10,11,12,13;
  2. int secondnumber = 1,2,3,4;
If you can't fix this, don't go any further.

This is how you read a number
  1. System.out.println("Enter firstnum: ");
  2. int fnum = QueenOfDaimond .nextInt();
  3. System.out.println("Firstnum: "+fnum);
Do the same for the second number.

Use if statements to check the numbers:
  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. }
  7. } else {
  8. // print fnum is not in range
  9. }

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
Reply With Quote Quick reply to this message  
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
 
0
  #18
Oct 31st, 2009
Thanks for the help and the advices

MJ
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: sairaarif is an unknown quantity at this point 
Solved Threads: 0
sairaarif sairaarif is offline Offline
Newbie Poster
 
-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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
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: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #20
Oct 31st, 2009
Originally Posted by sairaarif View Post
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
That question has already been answered.
This thread has 19 posts and you went and read only the first and skipped the rest?


Originally Posted by sairaarif View Post
Put up correct question..so that we can help u
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 595 | Replies: 19
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC