java - Illegal Start of Type and ";" Expected -
i'm trying write programme here , first started off 23 errors, managed downwards 7 errors have no thought how rid of them @ all. error messages follows:
exercise1lab5.java:58: error: illegal start of type else ^ exercise1lab5.java:58: error: ';' expected else ^ exercise1lab5.java:59: error: illegal start of type system.out.println("\nyou either old or young!"); ^ exercise1lab5.java:59: error: ';' expected system.out.println("\nyou either old or young!"); ^ exercise1lab5.java:59: error: invalid method declaration; homecoming type required system.out.println("\nyou either old or young!"); ^ exercise1lab5.java:59: error: illegal start of type system.out.println("\nyou either old or young!"); ^ exercise1lab5.java:65: error: class, interface, or enum expected } ^ 7 errors
my code is:
/** * @(#)exercise1lab5.java * * * @author * @version 1.00 2014/11/3 */ import java.util.scanner; public class exercise1lab5 { public static void main(string[] args) { scanner input = new scanner(system.in); float age, height, weight; string genderans, recordans, certans, courseans; char y, n, m, f; system.out.print("\nplease come in age: "); age = input.nextfloat(); if(age>=18 && age<35){ system.out.print("\nplease come in height: "); height = input.nextfloat(); if(height>=1.6){ system.out.print("\nplease come in weight in 'kg': "); weight = input.nextfloat(); if(weight>=100){ system.out.print("\nplease come in gender <m or f>?: "); genderans = input.nextline(); if(((genderans.equals('m')) && (weight<100) && (height>=1.85)) || ((genderans.equals('f')) && (weight<100) && (height>=1.6))){ system.out.print("\ndo have criminal record <y or n>?: "); recordans = input.nextline(); if(recordans.equals('n')) system.out.print("\ndid receive @ to the lowest degree d grade in pass irish gaelic in leaving cert <y or n>?: "); certans = input.nextline(); system.out.print("\ndo commit taking 10-week irish gaelic course of study on application <y or n>?: "); courseans = input.nextline(); } else system.out.println("\nyou cannot have criminal record!"); } else system.out.println("\nthus far not meet requirements!"); } else system.out.println("\nyou need under 100kg in weight!"); } else system.out.println("\nyou not tall enough!"); } else system.out.println("\nyou either old or young!"); } }
if shed lite on these errors , help me out, appreciate it, thanks!!
your brackets mismatched. here:
if(recordans.equals('n')) system.out.print("\ndid receive @ to the lowest degree d grade in pass irish gaelic in leaving cert <y or n>?: "); certans = input.nextline();
you need {
after if
.
sometimes these errors can confusing. tips:
start @ line error reported on , work backwards, checking subtle problems. use decent editor can show matched brackets. notepad++ selection basic editor. if editor supports auto-indentation, turn on. can grab things spotting problems indentation.you consider restructuring of code, if possible, clarify bit. example, if want insist entered age in range:
do { system.out.print("\nplease come in age: "); age = input.nextfloat(); } while (age < 18 || age >= 35);
after block of code, it's guaranteed age >= 18 && age < 35
.
java if-statement syntax-error
No comments:
Post a Comment