2 Replies - 451 Views - Last Post: 05 April 2011 - 05:22 AM Rate Topic: -----

#1 colintb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-April 11

Unit Converter

Posted 05 April 2011 - 05:09 AM

import java.util.Scanner;

public class milesToKilometer
{
	public static void main(String[]args)
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter Kilometers");
			
			Double Kilometers = input.nextDouble();
			
			
			
			System.out.println("Kilometers are"  + Kilometers);
			
				System.out.println("Enter miles");
			
			Double Miles = input.nextDouble();
			
			System.out.print("Miles are\n" + Miles );
			
			double milesconverted = 1.609 * Kilometers;
				System.out.print("Miles converted are\n" + milesconverted + "km" );
				
				/** Converts from miles to Kilometers */
  public static double milesToKilometers(double miles) {
    return 1.609 * miles;
  }

  /** Converts from kilometers to Miles */
  public static double kilometersToMiles(double kilometers) {
    return (1 / 1.609) * kilometers;
			
	}
	
}
}



Errors listed as illegal start of expression
class expected
Have tried checking classes and methods, perhaps i have repeated the method twice, but not sure.?

This post has been edited by macosxnerd101: 05 April 2011 - 06:20 AM
Reason for edit:: Title renamed to be more descriptive


Is This A Good Question/Topic? 0
  • +

Replies To: Unit Converter

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1357
  • View blog
  • Posts: 2,992
  • Joined: 05-April 11

Re: Unit Converter

Posted 05 April 2011 - 05:21 AM

Aren't your two methods inside your public static void main(String[]args) method? Try and move them outside :)
Was This Post Helpful? 1
  • +
  • -

#3 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Unit Converter

Posted 05 April 2011 - 05:22 AM

The public static double milesToKilometers method is located inside the main method scope.
You have to close the main method first, and then declare other methods. like so:

public class X {//start class X

  public static void main(String[] args){//start main..
    //code..
  }//close main scope

  public void someMethod(){//start someMethod
    //..code
  }//close someMethod scope

}//close class X scope

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1