while (gamesPlayed<gameQty) {
userChoice = JOptionPane.showInputDialog("Rock, Paper, or Scissors?");
//Determine winner for each game
if (compChoice.equalsIgnoreCase(userChoice));
[Code] ....
It seems to circle through the loop gameQty times, without comparing.
I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:
private void readtextfile() { try { Scanner rd = new Scanner( new File("filename")); List<String> lines = new ArrayList<String>(); while (sc.hasNextLine()) { lines.add(sc.nextLine());
[code]...
how to make each of the words to have a score of zero 0?
I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:
aadafbd dsfgdfbvc sdfgyub fhjgbjhjd
my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).
In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:
<sql:query dataSource="${user}" var="result"> SELECT * from users where email = ${sessionScope.email}; </sql:query>
import java.util.Scanner; public class Try{ static String name; static int age; static Scanner a = new Scanner(System.in); static Scanner b = new Scanner(System.in); static Scanner c = new Scanner(System.in); public Try(String name, int age){
[Code] ....
I was trying to make a program that asks the user to create a person or a group of persons and assign names and age to them. So I made a constractor "Try" and a method "AskUser".in AskUser() I use a do/while loop where user is asked to input a name, an age and if he likes to create another person. Now how do I take the input data each time the loop runs, and send it to constractor to create new objects with it? And how these new objects will be called?
I am able to get output from my constructor when I place a loop inside of it. However when I try to access the private variable that I thought was set by the constructor I get nothing. When I check its size it is zero as well.
Java Code:
public class WinningHand extends PokerCalculator { private int p1Size; private int p2Size; private String[] p1Hand = new String[p1Size]; private String[] p2Hand = new String[p2Size];
I have a program that using one JFrame which opens one of two JDialog windows depending on which button is pressed.
How do I assign listeners to the buttons and fields on the JDialog window? I added listeners on the View end, but how do I process them? I tried adding the '..implements ActionListener" class in the main Controller but it does not recognize/hear anything.
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random; public class test4 { public static void main(String[] args) { Random random = new Random(); for(int i =0; i < 1; i++){ int num = random.nextInt(10) + 1; System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?"); } } }
I have been asked to write a library program that will keep record of books and the year it was published. The program should ask the user how many rows he wants accept the string input from the user and display them in rows and columns. This is how i code it
package multidimension; import java.util.Scanner; public class bookrecords { public static void main(String[]args){ //declaring a scanner variable Scanner input =new Scanner(System.in);
byte b = 100; it works (implicit conversion of implicit int literal 100 to byte.
But if you have a methodvoid bla(byte b){}
And want to invoke it with a literal (which is an int by default):bla(8) then there is no implicit conversion.
Is the byte b = 100; just an exception in Java? And is it the rule that one has to explicitely cast (narrow) integer literals when passing to smaller-than-int types?
I am looping through data in Android, using Parse data. I came up with this as a way to get user information; the larger goal is to create a model of data that I can use in an array adapter, so I can create a custom list view (as described here [URL] .... In the example, the data are hard-coded, not pulled from a database.
public static ArrayList<Midwifefirm> getUsers() { //Parse data to get users ParseQuery<ParseUser> query = ParseUser.getQuery(); query.orderByAscending(ParseConstants.KEY_PRACTICE_NAME); query.findInBackground(new FindCallback<ParseUser>() {
[Code] ....
The intention is that for every user that does not have the type patient, collect this data about them, then store it in the arrayList.
On the return statement, though, there is an error: cannot return a value from a method with a void return type.
I may be over complicating this...read through various sources to get a model for this...in the end, I want to display a list of information about specific users, after the user makes a selection of a city...it would therefore display all the information about the medical practices in that city.
I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.
I have an requirement of splitting a Date-Time String i.e. 2013/07/26 07:05:36 As you observe the above string has Date and Time with space in between them.
Now I want just want split the string not by delimiter but by length i.e. after 10th place and then assign it to 2 variable i.e. Date <----2013/07/26 and Time <---07:05:36 separately.
Its supposed to notify the user if they have a palindrome, but keeps returning true even when I type, "hello".
import java.util.Scanner; public class PalinDrome { public static void main(String[] args) { String line; Scanner input = new Scanner(System.in); System.out.print("Please enter a word ");
I need my code to print out the top three most common IP Addresses in the ArrayList. Right now I have it printing out the top IP Address. I am a little confused as to how to get it to print out three. Every time I change something, It doesn't give me the correct results
My Code: public class Log_File_Analysis { private static ArrayList<String> ipAddress = new ArrayList<>(); private static String temp , mostCommon; static int max = 0; static int num = 0;
public static void main(String[] args) throws Exception { String s = "oldString"; reverse(s); System.out.println(s); // oldString } public static void modifyString(String s) { s = "newString"; System.out.println(s); // newString }
I thought the first print statement would print "newString" as String is an object, and when we pass objects between methods, changing state of the object in any method reflects across the methods.
So the while loop I am trying to use is: while( type != "EXIT" ) { type = input.next(); }
The problem is that typing in EXIT doesn't end the loop like I want it to. I also tried input.nextLine(); but neither of them work. The loop is being used to fill an ArrayList so the number of elements can change based on how many they want. What am I doing wrong, or what alternatives do I have?
covers switch statements and if/else statements. Java doesn't like the Strings for some reason. My instructor does her strings just like this and it works for her. I can figure out the rest of the program if I can only get around the: "java error35: sSymbol variable might not have been initialized.
import java.util.*; public class RockPaperScissors { public static void main(String[] args) { //generate outcome int symbol = (int)(Math.random() * 4); String sSymbol;
I am making a simple calculator. I want the user to input either string "add" or "subtract" and then it will take two numbers and either add or subtract them. I cannot get the if statement to work with a string!
import java.util.Scanner; public class newcalc { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter add or subtract");
Im trying to make a question game, much like a spin off from Trivial Pursuit. In this code, I call classes to get a random number. This number determines what category the question will be from. Coinciding with this number, the "if" statements go and pull the questions and answers from an alternate class. My problem is that when I try and output what should be the question and the 3 answers, its outputs "null" for each String?
This is my first class, which is just the class for the player.
Java Code: /* * To change this template, choose Tools | Templates * and open the template in the editor. */