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

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.

This program can compile and run.Don' t have program error.You should check other.

Yes, sandar it can compile. What I am asking is is there better way to do it?

Thanks

MJ

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

Sorry for the double posting but a better way would be:

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);
}
}
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

Thanks JavaAddict
That's exactly what I needed.
Cheerz MJ

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

the time multiplied by 80

It's not that difficult. Multiply time by 80 and put it in the distance

It's not that difficult. Multiply time by 80 and put it in the distance

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

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

Your question doesn't make sense.

int distance = 80 * time;
// or
int rate = 80;
int time = ...;
int distance = rate * time;

Your question doesn't make sense.

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

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);     
    }
}

What do you mean by "X".
Maybe this:

number " + loops + " " + loops + " [B]x[/B] " + num + " = " + result);

What do you mean by "X".
Maybe this:

number " + loops + " " + loops + " [B]x[/B] " + 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

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([B]"Hello World"[/B]);

System.out.println([B]"Row
number "[/B] + loops + [B]" "[/B] + loops + [B]" x "[/B] + num + [B]" = "[/B] + result);

The loops, num ,results are variables. Did you try to run it and see what it prints?

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

You know very well that this is not the way to declare variables:

int firstnumber = 1,2,3,4,5,6,7,8,9,10,11,12,13;
int secondnumber = 1,2,3,4;

If you can't fix this, don't go any further.

This is how you read a number

System.out.println("Enter firstnum: ");
int fnum = QueenOfDaimond .nextInt();
System.out.println("Firstnum: "+fnum);

Do the same for the second number.

Use if statements to check the numbers:

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

Thanks for the help and the advices

MJ

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

commented: Totally unecessary post -1

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.