I just need to write a simple program/function that replaces certain letters from a string (i.e. censor( "college", "aeiou" ) returns "cllg"). I'm trying to get the code right first, and then write a function for it.I basically just thought that I would iterate over the first string, and once I had the first character, I would then iterate over the second string, to see if the character exists. I'm getting a "dead code" error on my second loop because I put the second "break."
public class ap { public static void main(String [] args){ String s = "Hello"; String s2 = "aeiou";
I want to remove all numeric number in String text
String text = She was born in 1964,and now her age is 55; String delim = ","; StringTokenizer stringTok = new StringTokenizer(text, delim); String f1 = "%-40s"; String h1 = String.format(f1, "Token list");
I am using a TreeSet to tokenize a string. The output is sorted with numeric first followed by words
E.g. 13 26 45 and before etc.....................
Is there a tidy way to remove the numeric?
Last bit of my code is :-
// print the words separating them with a space for(String word : words) { System.out.print(word + " "); } } catch (FileNotFoundException fnfe) { System.err.println("Cannot read the input file - pass a valid file name"); }
So basically, if a line in a text file contains a certain string, that specific line will be deleted. It should probably be similair to this method?
Java Code:
/** * Replace text. * @param replace * The text to replace. * @param replaceWith * The text to replace with. */ public static void replaceSelected(String replace, String replaceWith) { try { BufferedReader file = new BufferedReader(new FileReader("data/replacer.txt"));
Question 1: I am working on an assignment where I have to remove an item from a String array (see code below). When I try to remove an item after entering it I get the following error "java.lang.NullPointerException." I am not sure how to correct this error.
Question 2: In addition, I am having trouble figuring out how to count the number of occurrences of each string in the array and print the counts. I've been looking at other posts but they are more advanced and I have not yet learned how to use some of the tools they are referring to.
private void removeFlower(String flowerPack[]) { // TODO: Remove a flower that is specified by the user Scanner input=new Scanner(System.in); System.out.println(); System.out.println("Please enter the name of the flower you would like to remove:
so my task is to write a code which would ask user to input the year as integer and first three letters of the month with first being an upper case letter. Than the program would determine the number of days for given year and month.
Currently I have a brain crash on how to check, if the user has provided the month with first character being upper Case. If not, than the program would automatically correct the character. Problem starts at line 17.
import java.util.Scanner;
public class DaysOfMonth4_17 { public static void main (String[] args) { //Initiate scanner Scanner input = new Scanner (System.in); //Ask for year input and use is as INT System.out.println("Enter the year");
the number of occurrences of a specified character in a string...i tried to do the program occurrences in a given string and i tried the code as below.
code:
import java.util.*; public class Occurrence { public static void main(String[] args) { Scanner input = new Scanner(System.in);
I have to create a code that can calculate the number of upper case letters in a string that is entered by the user (below.)
Java Code:
import javax.swing.JOptionPane; public class mainClass { public static void main (String [] args) { String userInput; userInput = JOptionPane.showInputDialog("Enter a string.");
[Code] ....
My issue is that I would like the program to be able to function properly when spaces are entered into the string. As it is right now, I believe it is only processing the first string entered into the input box.
Which string method to search a particular character in a string whether a particular character is there or not . Suppose my String is like............
String s = "Java.";
How I can find the character " . " in above string "Java." is present or not . What is the string method to search that "."
What should be the code if i want to input a different string in case of the typed string. The case is : I have a predefined string S = "Peter,please answer my question" and now when i input another string inside the text field character by character i want characters from the string S to enter instead of the input string. In short, the input string should be disguised as string S.
Here i want to print the String from Starting character which is given by user..Here i given below the image like my concept..here we put .(dot and enter R)eclipse will print the method name which is starting from R..
I have to write some code to take names from the user and then order them in alphabetical order and then print them out which i have managed to do. However, i can't get it to count the characters in the names that the user enters or count the amount of vowels in the names.
This is the code ive written:
import javax.swing.JOptionPane; import java.util.Arrays; String[] names = new String[9]; int i; names[0] = JOptionPane.showInputDialog("Please enter a name"); names[1] = JOptionPane.showInputDialog("Please enter a name");
As you notice, each character is seperated by a hyphen (serving as its delimiter). I want to only go through 10 lines in the text, instead of all 20 of them. So, I wrote the program in such a way that I intend to reach into the indices of each character in the text file. Since there are six characters in each line so that means there are 6 indices - and there are 10 lines I only want to go through. So, 6 indices times 10 lines equals 60 indices. Hence, there are only 60 indices I need to go through. In that manner, it's like I have gone through only 10 lines through that way.
It compiled perfectly fine but upon running it, I ran through an error in the black DOS screen that says
"java.lang.ArrayIndexOutofBoundsException: 6 ".
How do I work around that?
The code I wrote is shown below...
import java.io.*; import java.util.*; public class hotandcoldclusterdeterminer_test { public static void main (String args [])throws IOException {
The String class stores the characters of the string internally as a private char[] and calling someString.length() results in getting the length field from the character array. I am looking to get the details on how the length is implemented. I understand it is a field, but in the original question I provide sample code and really want to know if/how the resulting byte code may differ when compiled, perhaps I am just not seeing the simple answer through my confusion.
Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)
Example: Enter a string: "Hello, JAVA is my favorite programming language." Enter a character: e The number of times the specified character appears in the string: 3
I don't even know where to begin I've only got this
import java.util.Scanner; public class letterCounter { public static void main(String [] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string"); String myString = sc.nextLine(); System.out.println("Enter a letter"); String letter = sc.nextLine(); } }