Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: problems about methods....cant apply the continue y or n..

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problems about methods....cant apply the continue y or n..

    import java.io.*;
     
    public class meth
    {
    	private static int r=0;
    	private static int q=0;
    	private static int b;
    	private static int y;
    	private static int hg;//Random Number
    	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	static public void main(String[]haha)throws Exception
    	{
    		int a=0;//Guess Result
    		System.out.println(g());
    		//g();
    		//do{
    		while(a!=31)
    		{
    			q++;
    			try
    			{
    				System.out.println("Guess a Number");
    				b=Integer.parseInt(br.readLine());//Random Guess
    				a=f(b);//Check Guess,Random Guess
    			}
     
    			catch(Exception e)
    			{
    				r++;
    				System.out.println("Invalid Input");
    			}
            }
    	}//while(cx(true));}
     
    public static int g()//Get Random Number
    {
    	hg = (int)(Math.random()*31);//Random Number
    	return hg;
    }
     
    public static int f(int y)//Check Guess,Guess
    {
    	if(y>hg)
    	{
    		System.out.println("Lower");
    		return y;
    	}
     
    	else if(y<hg)
    	{
    		System.out.println("Higher");
    		return y;
    	}
     
    	else if(y<0)
    	{
    		System.out.println("Negative Number is not Allowed");
    		return -0;
    	}
    	else if(y==hg)
    	{
    		System.out.println("Yes The Random Number is: "+hg);
    		System.out.println("Number of Tries: "+q);
    		if(q==1)
    		{
    			System.out.println("Bravo It's Free");
    			q=0;
    			System.out.println(q);
    		}
    		int v=q*50;
    		int k=r*30;
    		int c=k+v;
    		System.out.println("Please Pay: "+v+" For Wrong Guess");
    		System.out.println("Please Pay: "+k+" For Wrong Input");
    		System.out.println("Please Pay: "+c+" Overall");
     
    		return 31;
    	}
     
    	else
    	{
    		return y;
    	}
    }
     
    public static boolean cx(boolean ay)throws Exception
    {
    	System.out.println("Try Again Y or N?");
    	String i=br.readLine();
     
    	if(i.equalsIgnoreCase("y"))
    	{
    		ay=true;
    		return true;
    	}
     
    	else if(i.equalsIgnoreCase("n"))
    	{
    		ay=false;
    		return false;
    	}
     
    	else
    	{
    		ay=false;
    		return false;
    	}
    }
    }
    Last edited by jps; August 21st, 2013 at 05:49 PM. Reason: code tags


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: problems about methods....cant apply the continue y or n..

    Please post your code in code tags.

    Ask a specific question, pointing to the area of the code with which you need help. Don't expect us to interpret the thread title correctly and then search through a hundred or so lines of unformatted code to find an area that might - just might - be related to the question. Make helping you easy or as easy as possible.

    And give your classes, variables, and methods better names, respecting Java's naming conventions. What value is there in naming a method 'f' or 'cx'? Worthless.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    jps (August 21st, 2013)

Similar Threads

  1. [SOLVED] Having problems understanding String Methods
    By kissyfurs in forum Java Theory & Questions
    Replies: 5
    Last Post: July 10th, 2013, 07:50 PM
  2. [SOLVED] Trying to apply methods to sequential program. Getting error.
    By Praetorian in forum Object Oriented Programming
    Replies: 0
    Last Post: May 4th, 2013, 11:26 PM
  3. Inheritence and problems with static methods.
    By Sylis in forum What's Wrong With My Code?
    Replies: 15
    Last Post: November 4th, 2012, 02:13 AM
  4. How to apply RowFilter in JXTreeTable
    By skmoorthy02 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 27th, 2011, 12:49 PM
  5. Overriding methods declaration problems
    By TurboTuring in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 9th, 2010, 11:23 AM

Tags for this Thread