Input from the keyboard

Hi

Ive been asked to create a program that prompts the user for 3 doubles, it will then display these number and then add/multiply and divide them. The math part of the program works but reading in from the keyboard doesnt work correctly.

Ive scanned the forums and notice alot of advise is given to :

http://java.sun.com/docs/books/tutorial/essential/io/streams.html

which im in the process of going through and to use:

import java.util.Scanner;

In my workbook all the examples so far havent mentioned the Scanner utility and any keyboard inputs have either been done like ive done or by creating an array:

double[] values = new double[3]

double counter = 0;

for(int x= 0; x < 10,x++){

System.out.println("Enter first number" + (x + 1));

Values[x] = (double) System.in.read();

System.in.read;

System.in.read;

My actual program:

public class Sums

{

public static void main(String args[]) throws java.io.IOException

{

double DisplayAdd;

double DisplayMultiply;

double DisplayDivide;

double firstnumber;

double secondnumber;

double thirdnumber;

firstnumber = 0;

secondnumber = 0;

thirdnumber = 0;

System.out.println("Enter first number");

firstnumber = (double) System.in.read();

System.in.read();

System.in.read();

System.out.println("Enter second number");

secondnumber = (double) System.in.read();

System.in.read();

System.in.read();

System.out.println("Enter third number");

thirdnumber = (double) System.in.read();

System.in.read();

System.in.read();

System.out.println("The numbers are:" + firstnumber + "and" + secondnumber + "and" + thirdnumber);

DisplayAdd = firstnumber + secondnumber + thirdnumber;

System.out.println("The total of the numbers added is:" + DisplayAdd);

DisplayDivide = firstnumber/secondnumber/thirdnumber;

System.out.println("The total of the numbers divided is:" + DisplayDivide);

DisplayMultiply = firstnumber * secondnumber * thirdnumber;

System.out.println("The total of the numbers multiplied is:" + DisplayMultiply);

}

}

Many thanks

[2273 byte] By [picklebeakera] at [2007-11-27 10:55:40]
# 1

http://www.javaworld.com/javaworld/jw-03-2001/jw-0302-java101.html?page=2

SidGatea at 2007-7-29 11:57:56 > top of Java-index,Java Essentials,New To Java...