| | |
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
I'm too new in java and I always appreciated when you share with me your knowledge. Here I'm trying following self-test exercise;
Give two declaration for two variables called feet and inches.Both variables are of type int and both are to be initialised to zero in declaration.
I try this way and it's compilable !! but not sure....did I miss something?
public class feetInches
{
public static void main(String [] args)
{
int feet = 0;
int inches = 0;
int totalFeet = inches * 12;
System.out.println("5 feet is " + 5* 12);
}
}
Thank you in advance
MJ
Give two declaration for two variables called feet and inches.Both variables are of type int and both are to be initialised to zero in declaration.
I try this way and it's compilable !! but not sure....did I miss something?
public class feetInches
{
public static void main(String [] args)
{
int feet = 0;
int inches = 0;
int totalFeet = inches * 12;
System.out.println("5 feet is " + 5* 12);
}
}
Thank you in advance
MJ
0
#2 Oct 29th, 2009
•
•
•
•
I'm too new in java and I always appreciated when you share with me your knowledge. Here I'm trying following self-test exercise;
Give two declaration for two variables called feet and inches.Both variables are of type int and both are to be initialised to zero in declaration.
I try this way and it's compilable !! but not sure....did I miss something?
public class feetInches
{
public static void main(String [] args)
{
int feet = 0;
int inches = 0;
int totalFeet = inches * 12;
System.out.println("5 feet is " + 5* 12);
}
}
Thank you in advance
MJ
This program can compile and run.Don' t have program error.You should check other.
0
#4 Oct 29th, 2009
Java Syntax (Toggle Plain Text)
public class feetInches { public static void main(String [] args) { int feet = 5; int feetToInches = 12; int inches = feet * feetToInches ; System.out.println(feet + " feet is " + inches); } }
If you want the user to enter input then search this forum for the Scanner class
Check out my New Bike at my Public Profile at the "About Me" tab
0
#5 Oct 29th, 2009
Sorry for the double posting but a better way would be:
Java Syntax (Toggle Plain Text)
public class feetInches { public static final int FEET_TO_INCHES = 12; public static final double INCHES_TO_FEET = 1.0/12.0; public static void main(String [] args) { int feet = 5; int inches = feet * FEET_TO_INCHES ; System.out.println(feet + " feet is " + inches); } }
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
#6 Oct 29th, 2009
•
•
•
•
Java Syntax (Toggle Plain Text)
public class feetInches { public static void main(String [] args) { int feet = 5; int feetToInches = 12; int inches = feet * feetToInches ; System.out.println(feet + " feet is " + inches); } }
If you want the user to enter input then search this forum for the Scanner class
That's exactly what I needed.
Cheerz MJ
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#7 Oct 29th, 2009
would you mind also to help me this:
Write Java assignment statement that will set the value of the variable distance to value of the time multiplied by 80. All the variable are of type int.
public class timetoDistance
{
public static void main(String [] args)
{
int time;
Int distance;
}
}
???
Thank you in advance
Write Java assignment statement that will set the value of the variable distance to value of the time multiplied by 80. All the variable are of type int.
public class timetoDistance
{
public static void main(String [] args)
{
int time;
Int distance;
}
}
???
Thank you in advance
0
#10 Oct 29th, 2009
•
•
•
•
JavaAddict,
sorry, to disturb you again. How can I build without having rate? e.g.
rt=d (rate multiplied by time = distance)
Thank you in advance
MJ
Java Syntax (Toggle Plain Text)
int distance = 80 * time; // or int rate = 80; int time = ...; int distance = rate * time;
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: 596 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working






