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.
So I have an array which holds 19 elements, each element represents a value of 'income'. I'm trying to code the graph so that each bar will represent the value of each element of the array (income). I have been given the code ' for (int Bar = 0; Bar < array of values.length; bar++);' however i'm unsure if this is how to do it, or what to add to this code to make it work.
I was told to design a class named Rectangle to represent a rectangle.The class contains:
■ Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. ■ A no-arg constructor that creates a default rectangle. ■ A constructor that creates a rectangle with the specified width and height. ■ A method named getArea() that returns the area of this rectangle. ■ A method named getPerimeter() that returns the perimeter.
Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.Here is my code for the Rectangle Class:
class Rectangle { double width; double height; public Rectangle() { width = 1; height = 1;
[code]....
The error that I am given when I compile the driver is as follows:constructor Rectangle in class Rectangle cannot be applied to given types; required: no arguments; found:int,int; reason: actual and formal argument lists differ in length.
2. Declare a class called Quadrilateral that can be used to represent a quadrilateral. What instance variables are required? This class should include the following methods:
• Accessor and mutator methods. Notice that negative and zero lengths should not be accepted. • A method called isParallelogram that returns a Boolean value indicating if the quadrilateral is a parallelogram. • A method called isRectangle that indicates if the quadrilateral is a rectangle. This method should invoke the method isParallelogram and return a Boolean value. • A method called isSquare that returns the Boolean value “true” if the quadrilateral is a square. This method should invoke the method isRectangle and return a Boolean value. URL...
import java.awt.Point; public class Quadrilateral{ private Point p1, p2, p3, p4; public Quadrilateral (Point p1, Point p2, Point p3, Point p4) {
I am creating a deck of 52 cards each with their rank(1 2 3...King, Ace) and suit(Clubs... Spades).
I want to be able to print out value of each card after creating them such as - 2 of CLUBS and so on. I am able to do that now. Only problem is, when it comes to the picture cards, I am representing them with numbers 11(Jack), 12(Queen) 13(King) and 14(Ace). I can't quite get around to changing the numbers to be represented as the actual words (King and so on).
I imagine that I should store the jack,queen,king,ace values in an enum too and call it in my loop but can't quite get it. Should I have like a 3rd for loop in my following codes to make it work?
Java Code:
//My main method. The Card class follows below
public static void main(String[] args) { Card[] cards = new Card[52]; int i = 0; for (Card.Suits suit : Card.Suits.values()) { for (int y = 2; y < 15; y++) { cards[i] = new Card(y, suit.name()); i++;
I am working on my project that uses elgamal elliptic curve. I know when the elgamal ec encrypt by following steps
Represent the message m as a point M in E(Fp). Select k ∈R [1,n−1]. Compute C1 = kP. Compute C2 = M +kQ. Return(C1,C2).
Where Q is the intended recipient’s public key, P is base point. My qusetion at number one.How represent m as a point. Is point represent one character or represent group of characters. also I need code by java done this issue like Koblitz Encoding Method for ECC
To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
How to reset the numbers to 0 in the final array ?
Create a class called DiceStatistics to represent a pair of dice and the totals of their rolls. It should have an array of two Dice as a private data member (these are the Dice from Problem 1). It should also have, as a data member, an array of integers to represent the possible totals of rolling two dice.
The class should also have the following methods:
initStats() to initialize all the totals to zero. rollOnce() to roll each die once, and add one to the correct totals element printStatistics() to print the number of times each total has come up over the number of runs.
Here is my code:
public class DiceStatistics { private final int NUMBER_OF_DICE = 2; private Dice[] dice = new Dice[NUMBER_OF_DICE]; private int[] totals; private int numberOfRolls;
[Code] ....
And here is the error:
run: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Dice.roll at DiceStatistics.rollOnce(DiceStatistics.java:27) at DiceStatistics.main(DiceStatistics.java:55) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
I know it has something to do with the fact that I need to somehow import the information from my first program "Dice" into this in order to actually get the dice statistics, but how do I do that?
I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."
It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.
I am trying to run a class with a client code and I get the following error
The method add(TimeSpan) is undefined for the type TEST
Why i get this error?
package timespan; // Represents a time span of hours and minutes elapsed. // Class invariant: minutes < 60 public class TimeSpan { private int hours; private int minutes;
We are doing a visualisation tool for point cloud research project. We use 3d sphere to represent each single point and when we have large number of points to display (~40,000), the rotation becomes very lagging.
What we have tried:
set JVM flag -Djavafx.animation.fullspeed=true, this worked a bit, but not significant.set JVM flag -Djavafx.autoproxy.disable=true, this did not work.
set Cache to true and CacheHint to Cache.SPEED, this did not make much difference.create another thread to do the rotation, and sync back after calculation, this did not work neither.
I want to write an application that inputs a sentence, tokenizes the words with method split and reverse the words (not the letters)...I am stuck at the last part: how to reverse them...should I use the method reverse(); ?
Here is my code..
import java.util.Scanner; import java.util.StringTokenizer; public class ReversedWords { //execute application public static void main( String [] args) { //get sentence
To delete "the" from string and display the new string my input------ the dog required output--------- dog my output-------------------thedog
Code :
import java.util.*; class the { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter a sentence"); String s=in.nextLine();
I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.
import java.util.Scanner; public class secret { public static void main(String args[]) { Scanner sc; char hidden='a'; String guess;
So I have to design a program that takes a word and reverses the order of it. The exact directions are:Write a recursive method void reverse() that reverses a sentence. For example:
[code = Java] Sentence greeting = new Sentence("Hello!"); greeting.reverse(); System.out.println(greeting.getText()); [/code] prints the string "!olleH".
Implement a recursive solution by removing the first character, reversing a sentence consisting of the remaining text, and combining the two. So basically my biggest issue is my method to actually reverse the word.
public class Sentance { private String Word; public Sentance (String aWord) { Word = aWord;
I am not very comfortable with Strings in Java. The problem I am facing is, taking a string that contains a sentence and reversing the words. Example would be, "Hi I am Bob" and changing it to "Bob am I Hi". Then returning the String.
My initial thoughts were to change the string into a character array and then manually doing the work with loops and tedious comparison statements. I quickly realized that there must be a better way but I am not very familiar with strings in Java to know what a more sufficient way would be.
i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner. if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing
public class Demo2 { public static void main(String[] args) { String s1="hi how are you"; s1=s1.replace('a', 'A'); s1 =s1.replace('e', 'E'); s1 =s1.replace('i', 'I');
[Code]...
this is working properly.
but when i trying with Scanner i am facing problem.
public class Demo2 { public static void main(String[] args) { java.util.Scanner scn= new java.util.Scanner(System.in) String s1=scn.next(); s1=s1.replace('a', 'A');
Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.
import java.io.*; class Sentence //The purpose of this program is to
The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?
Here is the main class:
public class MorseCode { public static String myInput; public static String[] myMorse; public static String myUserInput; public static char[] myAlph = {'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; public MorseCode()
My assignment is to write a program that will encrypt and decrypt a sentence entered by a user but the encryption is to be random using an array. Can I convert my sentence(string) from char to int then create a random array to encrypt?
import java.util.Scanner; import java.util.Random; /*SentenceEncryptionProgram */ public class SentenceEncryption { string sentence; //sentence entered by user