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.
*/
WAP which takes two string as input from the user (a & b).This prog should print two strings as output (a1 & b1).
(a1) should contain all the characters which are present in (a).but not present in (b). (b1)should contains all the characters which are present in (b).but not present in(a).
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).
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.
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");
I'm trying to calculate the average of grades that a user puts in. Here is my code so far:
public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println("Please enter an array of grades seperated bt a comma."); input.nextLine(); String arrayOfGrades = "100,50,100"; String[] grades = arrayOfGrades.split(",");
[Code] .....
I think I'm on the right track, the only big error I'm really getting is the line: sum += grades[i]. It's saying string can not be converted into a double.
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 did this using ArrayList<String> and my tests worked. Meaning I was able to read the strings in a different class through my constructor. However I want to use a string array because it will be easier to handle when I finish the program. I will send each players poker hand in and figure out who is the winner instead of putting it all onto a ArrayList and having to iterate through it. However whenever I did my check I am just printing null.
PokerFile class
void separateHands(String cards) { //ArrayList<String>playerOne = new ArrayList<String>(); //ArrayList<String>playerTwo = new ArrayList<String>(); String[] playerOne = new String[10]; String[] playerTwo = new String[10];
[Code] .....
ignore the boolean methods I was just building the structure of the program. The print file is what is outputting this:
null null null null null null
public class WinningHand extends PokerFile { //ArrayList<String> p1 = new ArrayList<String>(); //ArrayList<String> p2 = new ArrayList<String>(); String[] p1 = new String[6]; String[] p2 = new String[6]; WinningHand(String[] p1,String[] p2)
For one of my last labs for the semester, my professor is having the class go back to our very first program and apply some of the exception handling that we just recently learned about. Here's my improved code so far:
Java Code: import java.util.*; import java.lang.*; public class Lab2Part1 { public static void main (String [] args) { Scanner input = new Scanner (System.in);
[code]....
My code compiles fine, but even if I enter an integer or a double, it saves the number as a string, and prints that out as the name. Is there any way to get around this? Or do I need to use something besides a try-catch?
I am trying to add two strings to a hash map. the first being the key, a 3 digit code that can have duplicates, and the value to store in an ArrayList. From what I've read, when add a key to the hashmap that is a duplicate, the previous gets overwritten and that is why I am trying to put the values in an array list. I was hoping that when the key is looked up, it would print all the values associated with that key:
class library{ HashMap<String, ArrayList<String>> checkoutBooks = new HashMap<String, ArrayList<String>>() ; ArrayList<String> patName = new ArrayList<String>() ; public void checkoutBook(String isbn, String patron) { patName.add(patron) ;
We haven't covered BufferedReader in this course yet. The assignmen is to get user input to fill arraylist with strings then when user hits Enter without any input, the console displays the contents of the arraylist.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Ex01 { public static void main(String[] args) throws IOException {