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 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.
String a = "***************"; for(int i = 0; i++; i<10){
System.out.println(a); a = a - "*"; }
I searched about this online and read strings are unmutable in java but what does that exactly mean ? If the string cannot be changed how i am able to add the characters but not remove them.
public static void main(String[] args) { String[] a = new String[5]; //String input = JOptionPane.showInputDialog(null, "enter input"); Scanner scanner = new Scanner(System.in);
[Code] ....
I am trying to type in 5 strings from java console and print them all out. I am using a "/" as a delimiter. My problem is that it does not print any output after I type strings separated by "/" like this: hello/gea/cae/eaf/aer and press enter. It works if I use JOptionPane but from the console its not working. I want to use the console instead of JOptionPane for this one.
I am advised to use a while loop the Scanner method hasNextLine() and in the while loop body, call the Scanner method nextLine(), and add the returned String to the ArrayList of Strings. what I have gotten so far:
Scanner input = new Scanner(new File("")); while(input.hasNextLine()) { String line = input.nextLine(); System.out.println(line);
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?
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. */
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)