Tuesday, 15 January 2013

Java public static boolean method -



Java public static boolean method -

i want create little programme inquire 2 numbers first, checks whether or not using method, , then, after having lastly number, prints out result of method. (yes win, no lose).

i compared other questions on here, somehow can't work. made luckynumbers within method, outside method, bought "big java" i'm stuck on now.

help appreciated!

package wtf; import java.util.scanner; /** * * @author darl */ public class wtf { public static int luckynumber; public static int secondluckynumber; /** * @param args command line arguments */ public static void main(string[] args) { scanner sc = new scanner(system.in); system.out.println("give me number between 0 , 100 win prize. "); luckynumber = sc.nextint(); system.out.println("give me number between 100 , 200."); secondluckynumber = sc.nextint(); } public static boolean hasluckynumber(int luckynumber, int min, int max){ min = 20; //all winning tickets 20 till 60 max = 60; if (luckynumber > min || luckynumber < max) { system.out.println("unfortunatly, no prize"); }else{ system.out.println("you've got prize!"); } } public static boolean hassecondluckynumber(int secondluckynumber, int min, int max){ min = 140; // winning tickets 140 till 175 max = 175; if (secondluckynumber > min || secondluckynumber < max){ system.out.println("sad face"); }else{ system.out.println("we've got winner!"); } } }

for methods hasluckynumber(...) , hassecondluckynumber(...) have homecoming boolean value, either true or false. within main have alter implementation.

public static void main(string[] args) { scanner sc = new scanner(system.in); system.out.println("give me number between 0 , 100 win prize. "); luckynumber = sc.nextint(); if(hasluckynumber(luckynumber)) { system.out.println("give me number between 100 , 200."); secondluckynumber = sc.nextint(); if(hassecondluckynumber(secondluckynumber)) { system.out.println("we've got winner!"); } else { system.out.println("sad face"); } } else { system.out.println("unfortunatly, no prize"); } } public static boolean hassecondluckynumber(int secondluckynumber){ if (secondluckynumber > 140 || secondluckynumber < 175){ homecoming false; } else{ homecoming true; } } public static boolean hasluckynumber(int luckynumber){ if (luckynumber > 20 && luckynumber < 60) { homecoming true; }else{ homecoming false; } }

java methods boolean

No comments:

Post a Comment