Thursday, December 24, 2009

I have done this coding...but it give so many error..can show me where i'm doing wrong?

import java.util.Scanner;





public class Distance {


public static void main (String[] args) {





Scanner input = new Scanner (System.in);





System.out.print(';Enter a distance in a meter: ';);


Double meters = input.nextDouble();





do {


menu();





System.out.print(';Enter your choice: ';);


int choice = input.nextInt();





if (choice == 1) {


showKilometer(meters);


}


else if (choice == 2) {


showInches(meters);


}


else if (choice == 3) {


showFeet(meters);


} while (choice != 4) {


}


}


}





public static void showKilometer(Double meters) {





double kilometers;


kilometers = meters * 0.001;





}





public static void showInches(Double meters) {





double inches;


inches = meters * 39.37;





}





public static void showFeet(Double meters) {





double feet;


feet = meters * 3.281;





}





public static void menu() {





System.out.println(';1. Convert to kilometer \n2. Convert to inches \n3. Convert to feet \n4. Quit the program';);


}


}I have done this coding...but it give so many error..can show me where i'm doing wrong?
You need to declare choice outside your do while loop. And the syntax for a do while loop is:


do {


// the code you want in the loop


} while(choice != 4);

No comments:

Post a Comment