import java.util.Scanner;
public class Compute{
    public static void main(String[] args){
         Scanner input = new Scanner(Scanner.in);
        System.out.println("Enter three numbers");
        double.int= v0=5.5;
        double.int=v1=50.9;
        double.int = t= 4.5;
        System.out.println("5.5-50.9/(4.5)");
            }
        }

i am having trouble with writing this program, what am i missing to finding the average for this , or is it completely written wrong

Recommended Answers

All 8 Replies

Member Avatar for coil

There are a few problems:

Your syntax for declaring variables is wrong. Use:

[datatype] <variable name>=<value>

For example:

int i=5; //new int set to 5
double d=6.2; //new double set to 6.2
String s; //new string, value=null
s="Hello"; //assign value

Also, you need to calculate the average with your variables. Using fixed values doesn't do anything.

a double and an int are different data types, you can't use them together like that.

im just learning how to do this and i fixed that error, however the program has 1 error message poitning to the last curly brace. do you know of any books that break java down in simpler terms?

It could mean that you are missing a closing curly brace, or even misusing one. Without your updated source code, we would never know, but it is likely a separate issue than what you were having earlier.

There are any number of decent books to look at, but I would strongly suggest reading through online tutorials that provide the same purpose. Might I suggest the following:

http://download.oracle.com/javase/tutorial/java/nutsandbolts/index.html
http://www.javabeginner.com/learn-java/introduction-to-java-programming

and as always, no book or tutorial can replace attempting assignments and problems on your own and working through the difficult parts and exercising problem solving skills. There are just so many references available on the web I wouldn't even be able to post all the best ones. You should also start familiarizing yourself (after you go through the basics of programming syntax and statements) with the java docs:

http://download.oracle.com/javase/1.5.0/docs/api/
http://javadocs.org/

These will be your source for what every object is and what methods they have as well as what they pass and return. This is your Java Class index to all that is Java Classes.

import java.util.Scanner;
public class Compute{
    public static void main(String[] args){
         Scanner input = new Scanner (Scanner.in);

        double vo=5.5;
        double v1=50.9;
        double t=4.5;
        System.out.println("vo+v1/t");
        }
  }

this is what it looks like now

What error messages are you getting now? Also, I believe (I am not that experienced either) that by putting it all in quotes in your println, the calculation is not going to actually be done, but just show what would be done. Take the quotes out and it will perform the calculation. I put it into NetBeans and it is not showing any errors as written.

SergeantJoKer is correct, You only use quotes when printing strings. What you have there, will print vo+v1 to the console. It will not print the calculation. Remove the "" from the calculation and it will print the answer.

As a matter of fact, you should really initialise another variable to hold the average.
e.g.

double average = (v0+v1)/t;
System.out.println(average);

And by the way, check this out: http://www.wellho.net/regex/javare.html...focus your attention to the first couple of lines, you will see /t and what it does when used to print a string.

Also, please use code tags (just like Akill10 did) when you post your source to the thread. It makes them easier to read.

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.