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.
I am making a java text adventure and i am trying to add characters to it. I wrote it exactly the same as i wrote the items class (which works fine) but for some reason the character class keeps getting a null pointer exception when it gets to line 140 in the room class
characters.add(c); game class import java.util.ArrayList; import java.util.HashMap; /** * Game class for Free Willy Five: an exciting text based adventure game. *
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 have been working on this for hours and cannot get it to work properly. The program is to count the number of characters contained in both strings and display the results. It is also to display the final statement, but only once. This version has a complete statement for each matching character.
import java.util.Scanner; public class CountMatches { public static void main(String[] args) { String firstStr = (""); String s1 = firstStr;
Right now I have three stacks. Each stack holds characters, with the normal operations of pushing and popping. I am trying to compare two characters from stack1 and stack2(each character is a digit character). I would like to be able to do arithmetic on the digit characters and the push the answer on to a result stack.
Ex.) I pop character '3' from stack1 and '5' from stack2. Then I add the two. equaling '8' and pushing that character on to the result stack. This will hopefully in turn allow me to add arbitrary large numbers that integers will not support.
I am having trouble because I believe I am getting some ascii character values when I pop off the result stack. here is a small piece of my code
public void addition() { char temp1 ,temp2; int i = s1.getSize(); for(int j= 0;j<i;j++) { temp1 = s1.pop(); temp2 = s2.pop(); if(temp1+temp2>=10)
I feel like the program is written correctly; however, the interactions pane in DoctorJava gives me numbers instead of letters. I am happy that the numbers it gives me is consistent, but it still bothers me and I do not know what to debug.
import java.util.Scanner; public class Monogram { public static void main(String[] args) { Scanner input = new Scanner(System.in); String firstName, middleName, lastName; int nameLength=1;
Basically, there is a class "InfiniteInteger" which implements Comparable and can be used to store extremely long numbers as strings (i.e. "37493274839247923749234"). It has a couple functions such as "toString()", "compareTo()" and "isNegative()". Then there's the method I can't quite push through, "add(InfiniteInteger anInfiniteInteger)".Somewhere along the way, it just won't carry numbers correctly... It should work for positive and negative numbers but doesn't quite.
public InfiniteInteger plus(final InfiniteInteger anInfiniteInteger) { // TO DO String number1 = new String(string).replaceAll("-", ""); String number2 = new String(anInfiniteInteger.string).replaceAll("-", ""); int[] firstDigits = new int[number1.length()]; int[] secondDigits = new int[number2.length()]; int place = 0; for(int i = firstDigits.length - 1; i >= 0; i--) { firstDigits[place] = Integer.parseInt(Character.toString(number1.charAt(i))); place++; } place = 0; for(int i = secondDigits.length - 1; i >= 0; i--) { secondDigits[place] = Integer.parseInt(Character.toString(number2.charAt(i)));
[code]...
I can't use any external packages (i.e. Arrays, BigDecimal, ArrayList) and can't use long as a datatype either.
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
You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number. And, the operations must be done by adding or subtracting characters directly. You are not allowed to convert these strings to numbers before the operation.
The program must use a "Number" class which includes at least the following methods:
Number ( ); Number (double n); Number add (Number RHS); Number subtract (Number RHS); String toString ( );
This is what i have but it only adds positive numbers and it doesn't subtract problems like 7.05-8.96. Also some of it was what our teacher gave us like alignwhole method
import java.util.Scanner; public class Number{ private String whole; private String decimal; private String sign; public static void main (String[] args){ System.out.println("Enter two numbers");
You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number. And, the operations must be done by adding or subtracting characters directly. You are not allowed to convert these strings to numbers before the operation.
The program must use a "Number" class which includes at least the following methods:
Number ( ); Number (double n); Number add (Number RHS); Number subtract (Number RHS); String toString ( );
The below code is what our teacher gave us to start with, but it needs to add and subtract positive or negative numbers of any length. This code only adds positive numbers. Need to write code for subtraction .
Java Code:
import java.util.Scanner; public class Number{ private String whole; private String decimal; private String sign;
I am facing an issue with my java program, it is returning/storing file name with some junk characters i,e the file name with some '?','=' and '_'. Below is the example of file names.
Ex : abc.doc ab=?Windows-1252?Q?=c.do?c =?Windows-1252?Q? (prefixed with space) =?utf-8?Q? (prefixed with space) =?iso-8859-1?Q? (prefixed with space)
I was trying to create a java program which can remove the repeated characters in a String. For ex-
Input: kamehamehaaa Output: kameh
Here is my code:-
import java.util.Scanner; class replace { public static void main (String args[]) { Scanner br = new Scanner(System.in); System.out.println("Enter a word");
[Code] ....
On executing the program, StringOutOfBoundsIndex error occurs.
I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back
import java.awt.event.KeyEvent; public class UCC { private int xLoc; private int yLoc; private int xSpeed; private int ySpeed; private double gravity; private int size;
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).
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 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 tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.
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);
So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.
if (addrecord == true){System.out.printnl("record added");}
I close the interface then enter search for the record i just added using add record method but i do not find it what i am trying to say the added record using my application is not there. The question is how to save this record in the database ...