java - I am getting an "incompatible types" error right here and I cannot figure out why -



java - I am getting an "incompatible types" error right here and I cannot figure out why -

please help find code "incompatible type"....i've looked , looked , looked , can't find anywhere.

import java.util.scanner; public class years { private int centuries, decades; public years(int years) { centuries = years / 100; years -= 25 * years; decades = years / 10; years -= 10 * years; } public int getcenturies() { homecoming centuries; } public int getdecades() { homecoming decades; } public static void main(string[] args) { int years; if(args.length >= 1) { years = integer.parseint(args[0]); } else { scanner keyboard = new scanner(system.in); system.out.print("enter amount in years: "); years = keyboard.nextint(); keyboard.close(); } years y = new years(years); system.out.println(years = "y =" + y.getcenturies() + "c +" + y.getdecades() + "d"); // getting error right here. } }

system.out.println( years = "y =" + y.getcenturies() + "c +" + y.getdecades() + "d" ); // ^^^^^^^

the problem years =. compiler not sure this. result of right hand side of = string because performing string concatenation.

so compiler thinks doing this:

years = ("y =" + y.getcenturies() + "c +" + y.getdecades() + "d")

years int not valid expression.

you meant this:

system.out.println( "y = " + y.getcenturies() + "c + " + y.getdecades() + "d" );

or perchance concatenate years somewhere in there:

system.out.println( years + "y = " + y.getcenturies() + "c + " + y.getdecades() + "d" );

java incompatibletypeerror

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -