Click here to Skip to main content
15,888,106 members
Home / Discussions / Java
   

Java

 
QuestionHow do I add values in JTable Pin
Member 1114435716-Jan-15 4:35
Member 1114435716-Jan-15 4:35 
QuestionRe: How do I add values in JTable Pin
Richard MacCutchan16-Jan-15 4:51
mveRichard MacCutchan16-Jan-15 4:51 
AnswerRe: How do I add values in JTable Pin
Member 1114435716-Jan-15 9:17
Member 1114435716-Jan-15 9:17 
GeneralRe: How do I add values in JTable Pin
Richard MacCutchan16-Jan-15 22:30
mveRichard MacCutchan16-Jan-15 22:30 
GeneralRe: How do I add values in JTable Pin
Member 1114435717-Jan-15 7:27
Member 1114435717-Jan-15 7:27 
QuestionJava Pin
Angel Roy2-Jan-15 0:45
Angel Roy2-Jan-15 0:45 
AnswerRe: Java Pin
Richard MacCutchan2-Jan-15 4:56
mveRichard MacCutchan2-Jan-15 4:56 
QuestionHi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav1-Jan-15 18:10
Leela Krishna Yadav1-Jan-15 18:10 
This is like a number guessing game. The computer generates a random number between 1 to 100. The user has one number like 53 in his mind. And the example goes like this
example:

computer:75(random number)

User:higher(input which says 75 is greater than the user guess 53)

Computer:38(almost half of the first generated random number)

User: lower

Computer:57(like 38+(38/2))

User:higher

I want to implement like that but the code i am using is generating the values more than 75(random number) and getting more number of guesses to the user.

The computer asks a series of questions to arrive at the number the user has in mind. The user can only

respond with “higher”, “lower” or “yes”.

The game ends when the user responds with “yes” or “end”.

Example:
Example:

Note:
The program should be written to arrive at the answer asking the least number of questions.

Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class NumberGuess 
{

    public static void main(String[] args) throws IOException 
    {
        // TODO Auto-generated method stub
        int max=0,min=0;
        Random rand=new Random();
        
        int ComputerNumber=rand.nextInt(100);
        while(true)
        {
            System.out.println("Is the number:"+ComputerNumber);
            System.out.println("Please give higher or lower or yes:");
            InputStreamReader input = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(input);
            String value=reader.readLine();
            String yes="yes",lower="lower",higher="higher";
            int temp;
            if(value.equals(yes))
            {
                System.exit(0);
            
            }
            if(value.equals(lower))
            {
                int temp1=ComputerNumber;//57    
                temp=ComputerNumber+(rand.nextInt(ComputerNumber))+1;
                ComputerNumber=temp;
                System.out.println("New number:"+ComputerNumber);
            
            }
            if(higher.equals(value))
            {    
                int temp1=(ComputerNumber%10)/2-10;//59
                int temp2=(ComputerNumber/10)*10;
                temp=(ComputerNumber-rand.nextInt(ComputerNumber));
                System.out.println(temp1);
                System.out.println(temp2);
                ComputerNumber=temp2+temp1+1;
                System.out.println("New number:"+ComputerNumber);
            
            }
        }// end
    }//main end
}//


modified 2-Jan-15 11:13am.

QuestionRe: Hi friends I need some help regarding the following program will you please help me Pin
Richard MacCutchan1-Jan-15 22:30
mveRichard MacCutchan1-Jan-15 22:30 
AnswerRe: Hi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav2-Jan-15 4:42
Leela Krishna Yadav2-Jan-15 4:42 
GeneralRe: Hi friends I need some help regarding the following program will you please help me Pin
Richard MacCutchan2-Jan-15 4:54
mveRichard MacCutchan2-Jan-15 4:54 
GeneralRe: Hi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav2-Jan-15 5:14
Leela Krishna Yadav2-Jan-15 5:14 
AnswerRe: Hi friends I need some help regarding the following program will you please help me Pin
Richard MacCutchan2-Jan-15 5:46
mveRichard MacCutchan2-Jan-15 5:46 
GeneralRe: Hi friends I need some help regarding the following program will you please help me Pin
Leela Krishna Yadav2-Jan-15 5:59
Leela Krishna Yadav2-Jan-15 5:59 
QuestionHelp option in a JAR FILE Pin
ramina sen30-Dec-14 20:40
ramina sen30-Dec-14 20:40 
AnswerRe: Help option in a JAR FILE Pin
Richard MacCutchan30-Dec-14 22:09
mveRichard MacCutchan30-Dec-14 22:09 
GeneralRe: Help option in a JAR FILE Pin
ramina sen30-Dec-14 22:16
ramina sen30-Dec-14 22:16 
GeneralRe: Help option in a JAR FILE Pin
Richard MacCutchan30-Dec-14 22:47
mveRichard MacCutchan30-Dec-14 22:47 
Questionproblem to connect Java EE application to database Pin
Imad_dz29-Dec-14 6:31
Imad_dz29-Dec-14 6:31 
SuggestionRe: problem to connect Java EE application to database Pin
Richard MacCutchan29-Dec-14 23:13
mveRichard MacCutchan29-Dec-14 23:13 
Questionpagination in java swing Pin
bilalshameem25-Dec-14 23:44
bilalshameem25-Dec-14 23:44 
AnswerRe: pagination in java swing Pin
Richard MacCutchan26-Dec-14 1:05
mveRichard MacCutchan26-Dec-14 1:05 
Question[EDIT] CLASS cannot be resolved to a type Pin
AmbiguousName23-Dec-14 8:56
AmbiguousName23-Dec-14 8:56 
QuestionRe: CLASS cannot be resolved to a type Pin
Richard MacCutchan23-Dec-14 21:38
mveRichard MacCutchan23-Dec-14 21:38 
AnswerRe: [EDIT] CLASS cannot be resolved to a type Pin
alexey_s22-Jan-15 8:15
alexey_s22-Jan-15 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.