473,486 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Riddle Program using Arrays, HELP!

1 New Member
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class riddleGuess
  3. {
  4.   public static void main (String[] args)
  5.   {
  6.     Scanner myScanner=new Scanner(System.in);
  7.     String[] question= new String[5];
  8.     String[] solution= new String[5];
  9.     String userAnswer= new String();
  10.     int times; times=0;
  11.  
  12.     //initialize arays
  13.     question[0]=("I am weightless, but you can see me. Put me in a bucket, and I'll make it lighter. What am I?");solution[0]=("A hole");
  14.     question[1]=("I have hands that wave at you,/nThough I never say goodbye./nIt's cool for you to be with me,/nEspecially when I say, HI. What am I?  ");solution[1]=("an electric fan");
  15.     question[2]=("Pronounced as one letter,/nAnd written with three,/nTwo letters there are,/nAnd two only in me./nI'm double, I'm single,/nI'm black, blue, and gray,/nI'm read from both ends,/nAnd the same either way./nWhat am I?");solution[2]=("eye");
  16.     question[3]=("You use a knife to slice my head and weep beside me when I am dead. What am I? ");solution[3]=("An onion");
  17.     question[4]=("What is the best way to keep your hat from falling off your head?");solution[4]=("don't put it on your head");
  18.  
  19.     System.out.println("I AM THE SPHINX! PLAY MY GAME OF 5 RIDDLES AND I LET YOU LIVE! You've got three tries for each riddle!");
  20.     System.out.println("\n The first question is: \n" + question[0] + "\n");
  21.  
  22.  
  23.  for (times= 0; times < 3; times++)
  24.        String userAnwer=myScanner.nextLine();
  25.        System.out.println("You replied "+userAnswer); 
  26. }
  27. if (!userAnswer.equals(solution[0]))
  28. {
  29.        System.out.println("You got it wrong! Try again!");
  30. }
  31. else if (userAnswer==solution[0])
  32. {
  33.        times=4; System.out.println("You got it right!");
  34. }
  35. }-
Jan 15 '14 #1
1 2428
r035198x
13,262 MVP
You should use code tags when posting code. So what is the problem you are having with the code? Does it compile? Does it show errors when you run it?
Jan 15 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4943
by: hoover_richard | last post by:
I am a newbie to C++ and I need help with a simple program I am trying to write. My program is designed to print all of the odd integers contained in an array and output the sum of the odd...
16
3458
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
3
1608
Blackout
by: Blackout | last post by:
Hi, I'm new to C and need to make a program that displays the output of the first six powers of 2 like this: 1 2 4 8 16 32 (2 to the power of 0, 2 to the power of 1, 2 to...
16
2503
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
14
8006
by: xtheendx | last post by:
I am writing a gradbook type program. It first allows the user to enter the number of students they want to enter. then allows them to enter the first name, last name, and grade of each student. The...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.