Thread: help student
View Single Post
  #2 (permalink)  
Old 01-29-2008, 10:44 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Done first one
Hello jvasilj1

I fixed the first one for you:
Code:
import java.util.Scanner; // import Scanner // Convert from Meters to Feet and Inches The program should repeatedly input a length in meters and then print that length in feet and inches. public class MeterToFtIn { public static void main(String[ ] argv) { double meter, f, i; String more; // Should be a string Scanner con = new Scanner(System.in); //con is used in program, not "console" System.out.print("Do you wish to input another length in meters: "); more = con.nextLine( ); // Reading a String more = more.toUpperCase( ); while(more.charAt(0) == 'Y'){ // equals-equals is for comparing and equal is for assigning System.out.print("Enter length in meters: "); // double quotes here meter = con.nextDouble( ); double feet = meter * 3.28083989501312; f = (int) feet; int inches = (int) (12 * (feet - f) + 0.5); System.out.print("The length is "); if (feet == 1) System.out.print(feet + "foot "); else System.out.print(feet + "feet "); if (inches == 1) System.out.println(inches + " inch."); else if (inches < 1) System.out.println(inches + " inches."); else System.out.println("."); System.out.print("Do you wish to input another length in meters: "); more = con.next( ); more = more.toUpperCase(); // Brackets missing } } }
The first program should run now. Try to debug the second yourself. It is the best way of learning how to deal with the compiler error messages.

Good luck
__________________
If your ship has not come in yet then build a lighthouse.
Reply With Quote