So basically I have to create a java program that accepts a string and does the following:
1.) Insert a blank space before capital letters
2.) Convert any capital letters into lower case except the first letter(if it is capital).
So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.
Java Code:
import java.util.*;
public class WordSeparator
{
public static void main(String[] args)
{
String word1, word2;
Scanner userInput = new Scanner(System.in);
How do I code this without having the need to use iterator? Code a Java method that accepts an ArrayList of integers and an integer. The method should delete all elements in the array list exactly divisible by the integer and return the number of remaining elements.
So I was just wondering if it's possible to create a program with JAVA that uses an algorithm to summarize data inputed. I've never done something like this before, If this is not possible with Java is it possible with C++ or any other language??
i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..
I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.
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.
1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy 2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.
This is titled "Creating static methods that accepts arguments and returns a value". I think that I understood everything about this except for the very bottom part of the code. I wasn't really sure where to put it. From the errors that I am seeing, I know which line is giving the errors but I'm not sure what is wrong with it.
import java.util.Scanner; public class ParadiseInfo2{ public static void main(String[] args){ double price; double discount;
[Code] ....
Errors:G:ParadiseInfo2.java:29: error: illegal start of expression public static double computeDiscountInfo(double pr, double dscnt) ^ G:ParadiseInfo2.java:29: error: illegal start of expression public static double computeDiscountInfo(double pr, double dscnt)
Write a method named hopscotch that accepts an integer parameter for a number of "hops" and prints a hopscotch board of that many hops. A "hop" is defined as the split into two numbers and then back together again into one.For example, hopscotch(3); should print:
Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay (gross pay = hours worked * hourly rate), the tax withheld (tax withheld = gross pay * tax rate) and the net pay (net pay = gross pay - tax withheld).Use a named constant for storing the tax rate of 0.15
Here is my Code:
import java.util.Scanner; class Tutorial { public static void main(String[] args);
//Scanner Test String stream2 = "ab34ef 56"; // create a new scanner with the specified String Object Scanner scanner = new Scanner(stream1); // find a string "World"
[Code] ....
Matched expression found by findInLine: 34
ef56
is new line? right?
The java.util.Scanner.nextLine() method advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end.
then 56 is in new line and it must return ef.What is the problem?
I have to create a constructor with eight parameters containing both string and integers.the variables were supposed to be entered by user. but when I try to create an object of the class the IDE post error messages about the constructor.
public class hfiledriver { //the class name is hfile //after the main method I try creating an object of the class //after prompting the user to enter the data hfile hfile= new hfile(firstname, lastname, gender, age, weight, height); }
Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children. Don’t worry if the tree is unbalanced. Note that this will not be a search tree; there’s no quick way to find a given node. You may end up with something like this:
It also says all Letters must be Leaves
Now I had it almost similar to that picture, but it wasn't right. So ive been working on it but im getting some very strange (and frustrating) output from the following methods.
Ive included the display method just for reference. The book told me to use it so I haven't edited it. I believe my main issue is with my (incomplete) insert() method. The output goes into an infinite loop despite having a return statement break the while loop when a character is inserted.
The way I see to solve the problem is just add a (+) whenever a new subtree needs to be created. Say I add A and B, then it first creates a subtree at the root with a (+) and afterwards lists A and B as its leaves. If I insert a C, it should be able to simply move to the right child of the root and deposit the C there.
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?
Ive been trying to create a program to say how many 5cent,10 cent and 50 cent coins there are if you put a number in example 20. I used the init method because thats what the teacher told me to use but i have no clue on what to do.
I am now at the beginning trying to teach myself Java :) So far it has been good everything however now I came across the problem where I wanted to create payroll program for myslef based on one of the books I have.Somehow the issue in provided program code gives me the negative values on the salaryNett and valueTax:
Java Code:
import javax.swing.JOptionPane public class FinnancialApplicationPayroll { public static void main (String[] args){ String input = JOptionPane.showInputDialog (null, " What is your name");
I'm training myself with the EJB 3 technology. I would like to create a stateless bean that instead of returning a String, it returns an object. I tried in the same way I did with the first exercise, but I'm getting several errors.
I'm just learning about arrays. I have a small program to write that asks to create 2 arrays. One holding 5 names of flowers. One holding the prices of those 5 flowers. I ask the user what kind of flower they want and the quantity. I then need to create a loop that locates the flower name and uses that index to find the cost of the flower. I am struggling on how to write in code how to use one array index to find another. Example: Roses and $.50.
We have to create a program called MyStack.In Push: Add one element at the end of the buffer.In Pull: Remove one element from the end of the buffer. In isEmpty: Should check if the list is empty or not and return the result as a boolean variable.
I am totally confused, I wrote the buffer and the array, but how do i add an remove element from the buffer?How do i add an element? What Statement do i Use?
Java Code: public class MyStack<T> implements Stack<T> { private final T[] ringbuffer; int index = 0; int last;
I have spent the past 12 hours on it and have gotten no where. I need to create a program that will calculate different tax brackets. I have tried all combinations I can think of and can't get it to work!!! I am literally about to go insane! I need the program to calculate tax will be 1% for anything up to $50000. If the tax is over $50000, you keep that 1% of $50000 and then add the remaining. So for an income in the second range, it would be 1% of $50000, and then 2% of (income - $50000). This then continues for each range.
The problem I'm having is getting it to display the correct interest rates. I am not asking for you to write it for me. I want to learn. But at this point I have exhausted all resources available to me.
import java.util.Scanner; public class Project3taxinfo { public static void main(String[] args) { final double RATE1 = 0.01; //1% tax on the first $50,000 final double RATE2 = 0.02; //2% tax on the amount over $50,000 up to $75,000 final double RATE3 = 0.03; //3% tax on the amount over $75,000 up to $100,000 final double RATE4 = 0.04; //4% tax on the amount over $100,000 up to $250,000 final double RATE5 = 0.05; //5% tax on the amount over $250,000 up to $500,000 final double RATE6 = 0.06; //6% tax on the amount over $500,000