I am trying to update a Rubik's cubes side by adding each of the 9 squares of the Rubik's cube's side.
So for example:
cube.front.squares = cube.fronts.squares[1] + cube.front.square[2] + cube.left.sqaures[8] ... //until 9 sqaures are added, where squares is a String array of size 9. However, when I try doing this I get an error stating "change 'square' to 'String'". I know I can go in an individually change the values like:
I am having a problem with the following code. It compiles and runs fine however my output is wrong.
public class SplitString { public static void main(String[] args) { String[] string1 = split("ab#12#453", "#"); String[] string2 = split("a?b?gf#e", "[?#]"); for (int i = 0; i < string1.length; i++) { System.out.print(string1[i] + ",");
[code]....
The split method in the String class returns an array of strings consisting of the substrings split by the delimiters. However, the delimiters are not returned. Implement the following new method that returns an array of strings consisting of the substrings split by the matching delimiters, including the matching delimiters.public static String[] split(String s, String regex)For example, split("ab#12#453", "#") returns ab, #, 12, #, 453 in an array of String, and split("a?b?gf#e", "[?#]") returns a, b, ?, b, gf, #, and e in an array of String.
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'm stuck with the following error message when i try to convert a String to XML and back to a String.
Exception in thread "main" org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it. at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(Unknown Source) at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source) at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source) at com.innovatrail.consulting.xml.XMLTEST2.main(XMLTEST2.java:66)
Below is my Java code snippet: The code syntactically correct except line 66. If you comment out line 66 in the source code, everything works just fine. The XML representation of my input string is denoted by INPUT 1 and that of my output string is denoted by OUTPUT 2.
I want to clarify it whether this below code, when running this loop, will it create separate string objects as strings are immutable or else, will it keep the same reference(as each time inside loop, we use the same name 'rslt') and assign new string value for this?
I have this source code that is supposed to count the repeated occurrences of certain strings in the text file, "string.txt". The contents of the file are listed below:
Question: 1. Declare and implement a class named Substrings. The class will contain the following data members and methods:
Data members: string S
Methods: setS() take a string as a parameter and store it in S printSub1(), printSub2(), printSub3(), printSub4() print all substrings of S. If S = "abcd",
Alright so after doing some googling and watching tutorials I managed to put together the first two but I still don't exactly understand how nested for loops work, however just a single loop I do understand.
Secondly, the 3rd and 4th prints are completely destroying my brain using for loops, which we are supposed to use. Check out my code below, also keep in mind the 3rd is giving errors and the 4th i had to revert back to the same as the first print temporarily because my code because so messed up. How to understand nested for loops better.
[code=Java]
import java.util.Scanner; class subString { String S; void setSubstring(String SS) { S = SS;
[Code] .....
Compiling: error for myS.printSub3 and myS.printSub4 is the same as 1 because i had to revert it after ruining the code.
I'm attempting a small program as I'm teaching myself the ropes. In it, I need to compare one string (the base) to another which is just the base string that's had it's characters shuffled.
Java Code:
String base = "ABCDEFG" String shuffled = "CDAFBEG" mh_sh_highlight_all('java');
What I need to do is run a loop that shuffles the base string each time, but compares and saves any characters that match in the correct location. For example, if shuffled = "CDAFBEG", then the G would be "locked" in place and the rest of the characters shuffled and looped back to the comparison.
I have all the code I need for shuffling the string, but I'm not sure how I would go about comparing each character and then also locking it in place. I get the basics, I think, of needed to use several variables.
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;
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.
An array has objects with String firstName, String lastName, int ID, char examType('M' or 'F'), and int score. Every object has both Midterm('M') and Final('F'). The array has to be sorted by the first Midterm- 'M' and immediately followed by the Final ('F') of the same person (object). Im having troubles with coming up with a proper algorithm with gettin the Final- 'F' after Midterm for the same person.
Java Code: public static Exam[] collateExams(Exam[] exams) { Exam [] r = new Exam[10]; r = exams; int[] position = new int[10]; int index = 0; for(int i = 0; i < exams.length; i++)
I am working on an assignment where I initially have to take as input a number. That number will be the number of strings the user is going to type. As they are typed, they are to be sorted alphabetically, then printed. It took me a while to get this far, and I am stuck on how to properly invoke the other methods in main. There has to be at least three methods: main, one to do the sorting, and one to print the new array. I'm quite sure there are mistakes in my code, but this is definitely a challenge for me. Here is the code. Keep in mind that the methods being invoked are blank on purpose.
I am not allowed to use the Arrays, Arraylist or Collection class. This is basically to test my ingenuity and to see how arrays actually work.
import java.util.*; public class Sort_as_Inserted { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of elements to be sorted: "); String element_number = input.nextLine();
Every time i try and add a new word to personalDictionary, it only replaces the first index. In my personalAdd method i had tried to add a running count to advance the position it would be saving in but it doesn't seem to be working correctly...
Java Code:
import java.util.Arrays; import java.util.Scanner; import java.io.File; import java.io.PrintWriter; import java.io.FileNotFoundException; public class SpellingChecker
I'm writing a command line application of a calculator in Java. I need to be able to (as per program requirements) split the array of strings (6+3) into an array of strings? How would that be done? I know you can use the split method, but I am not really sure how that wold work to perform math with them?
On a side note: for this application, how could you make the program accept a variety of different lengths of strings to perform math with them?
Error:public String front3(String str) { ^^^^^^^^^^^^^^^^^^ This method must return a result of type String
Possible problem: the if-statement structure may theoretically allow a run to reach the end of the method without calling return. Consider adding a last line in the method return some_value; so a value is always returned.
I have got a pretty good framework working for my hangman game so far, however I am quite stumped on how to find multiple instances of the same letter in a single string. I am using indexOf to find the instance of a character in a string, but it only returns the first instance. So if the words(s) contain(s) multiple instances it doesn't register the rest.
public static void main(String[] args) { String word = "crazy horse"; String answer=""; String space=" "; String dash="-";
I have created an application using hibernate and struts.In which a form is created where the user will enter all its personal details(for e.g name ,phone no. and address).
Here for address I have used textarea and whenever user enters the address, sometimes it can be a long string also.
So the problem is if a long string is entered then while displaying that ,address comes on single line and the page is stretched.
how to break this single string into mutiple lines in java class?
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.