Loop printing twice java -
i have no idea why loop printing twice. have 2 separate classes have created , whatever reason cannot figure out why it's printing twice console. not sure if because called wrong in tabletest? or if had done wrong elsewhere. have run both in ide , command line , i'm still getting same issue.
public class tabletest { public static void main(string[] args){ int getbegin, getend; system.out.println("enter number start with: "); scanner input = new scanner(system.in); getbegin = input.nextint(); while (getbegin < 0){ system.out.println("please enter number greater 0."); getbegin = input.nextint(); } system.out.println("enter number end with: "); getend = input.nextint(); while (getend < 0 || getend < getbegin){ system.out.println("please enter number greater 0. or greater first input."); getend = input.nextint(); } multiplicationtable loop = new multiplicationtable(getbegin, getend); loop.printtable(getbegin, getend); } } public class multiplicationtable { public multiplicationtable(int begin, int end){ printtable(begin,end); } void printtable(int begin, int end){ system.out.println(string.format("%-10s %-10s %-10s", "number", "squared" , "cubed")); (int = begin; <= end; ++i){ system.out.println(string.format("%-10s %-10s %-10s", i, i* i, i*i*i)); } } }
your constructor in multiplicationtable calls printtable
method , call again in main method
Comments
Post a Comment