In c++, I'm aware that you can use the ignore function to ignore numbers after space, but in string how do I ignore a number after space is found for instance, "109 33" how would I ignore 33?
I'm trying to make a program that will count each letter like if I put the word
e-1 h-1 l-2 o-1
The problem I'm running into is that if I put something like How now, brown cow? It should give me something like this
b - 1 c - 1 h - 1 n - 2 o - 4 r - 1 w - 4
but it doesn't instead the whole program crashes because of the punctuation marks and the spacing. Is there a way for me to fix that? All I know is that it has something to do with the alphabet[pos(letter)]++;
import java.util.Scanner;
public class CharCount { static Scanner keyboard = new Scanner(System.in); //this method should allow the user to enter a line of text (that should all be lower case) and then go to the printResults method public static void main(String[] args) { String text, character; int count; char letter; int[] alphabet; System.out.println("Enter a line of text:"); text = keyboard.nextLine().toLowerCase();// any text entered will be lower case alphabet=countLetters(text);
I am working on my homework, and everything is fine. But I was wondering if I can fix one thing. basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{ static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { System.out.print("Enter the first name of the file: "); String input = kb.readLine(); int[] firstArray = readFile(input); firstArray = bubbleSort(firstArray);
Basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{ static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { System.out.print("Enter the first name of the file: "); String input = kb.readLine();
[Code] ....
As you you may figure, it works if I put numbers separated by each lines. I was wondering if I can change it so that it works when I put numbers separated by space rather then each lines.
The question is Write a program that displays all the numbers from 100 to 1000, ten per line, that are divisible by 5 and 6. and separated by exactly a space.
My assignment requirements are to display this in Dialog Box / message box . I have written this code so far
import javax.swing.JOptionPane; public class Exercise04_10 { public static void main(String[] args) { int count = 1; for (int i = 100; i <= 1000; i++) if (i % 5 == 0 && i % 6 == 0)
I'm trying to loop through a string and depending on the character, add a JLabel to a game. The problem is the character 'L' represents a lantern but is also used in the reply the game gives which is "LOOKREPLY". I've tried to use some code to ignore the LOOKREPLY bit but it's not working. Here's what I've tried.
But the first image on all of the JLabels is always a lantern, which is what L represents. As it's only 1 lantern this leads me to believe that it's ignoring the first 'L' but for some reason it's not ignoring the 'L' at the end of LOOKREPLY.
I have made a program, where the user types in a letter M, C or I to identify their major, if the user types m, c or i, my code does not work.
How could I make my program ignore if the letter is upercase or lowercase? My code is posted below. Can I do this in any easier way then adding this type of code for each lowercase letter?:
Java Code:
if (s.charAt(0) == 'm') System.out.print("Mathematics "); mh_sh_highlight_all('java');
My current code:
import java.util.Scanner; public class c4e18 { public static void main(String[]args){ Scanner input = new Scanner(System.in); System.out.print("Enter two characters: "); String s = input.nextLine(); if (s.charAt(0) == 'M')
I have several Buttons wrapped into a VBox. I used setOnSwipeUp and setOnSwipeDown for up and downs the buttons. But when there is no more buttons the scroller continues but shows nothing, is empty. How do I do when there are no more buttons ignore swipe gestures?
[Java] // Menu Swipe Up menubox.setOnSwipeUp(new EventHandler<SwipeEvent>() {
I have an assessment for college, the part of my code that im struggling with is the part where the user enter their first name followed by a space and then their second name. I m using ---------------fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); ------------- to capture this. the issue is if the user only enter 1 name I need to output an error. the issue is I cant find a way to tell if the user entered a second name. This is what I have so far:
public void makename() { // makes an inputbox to ask their name fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); //separates the first and second name into 2 strings in order to make the username
[code]....
The problem is it accepts anything I type in without causing an error. What should I type in to stop this? ive tried anything but I cant find a way to tell if a surname has been entered or not.
eg.ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.
inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character. Any other sequence should return an error message and a way of entering it correctly.
Having read in the list (or during the reading of the list) the program is to find the longest continuous occurrence of consonants, outputting the vowels between which this occurs and the length of this string of consonants.
{In the example above, the output would be 13ou}
Check for input errors and respond accordingly.
I have done most of it, the problem being that I don't know how to end the scan with a space so that I don't have to press enter. I have done the bit that finds the biggest amount of consonants in a row. (I'm writing in netbeans)
I have been trying to space out output on a Java console window so that I have three columns with 6 rows of data from three different arrays. The code I have so far outputs the data with no problem however the spacing between the columns is uneven. My loop so far is made up as follows
for (int i = 0; i < printVotes.length; i++) { System.out.println(printNames[i] + " " + printVotes[i] + " " + printPrecent[i] + "%"); }
As you can see I have been manually adding the space between each element of the array but this means that the space between each element is different because the size of each element is different if work out a loop that works out an even amount of space between the elements and then print this along with the elements ....
I want to cut my string from space char but i am getting exception....
Java Code:
import java.util.Scanner; import java.util.StringTokenizer; public class NameSurname { public static void main(String args[]) { Scanner sc=new Scanner(System.in); String s0,s1=null,s2 = null,s3=null; s0=sc.next();
[Code] ....
Console: Lionel andres messi Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at java.util.StringTokenizer.nextToken(Unknown Source) at com.parikshak.NameSurname.main(NameSurname.java:15) mh_sh_highlight_all('java'); I/p -O/p:
my s0=Lionel andres Messi
And I want to break it as soon as i find space and save it in s1,s2 and s3
I'm working on this space invaders game and I've been stuck trying to get the alien spaceships to move down in one group. The way we have to design the game is we have to implement at least these 3 classes. These classes are GameData,GamePanel, and Animator. GameData is all the action figures/models in the game. GamePanel draws all game action figures/ models on the screen. Animator updates periodicaly action figures positions,sizes, colors etc. I can get the aliens to move right but once they hit the end of the canvas I cannot figure out how to get them to move as a group down and then begin moving left. I tried to add alien objects to the GameFigures list and then have the update method in the Alien class be responsible for moving the alien ships, but I couldn't figure out how to make it work. So then I made an alienFigures list in the GameData class and I still cannot figure out what to do. Here is the GameData class
I started using Java a couple of days ago, If you haven't guessed I want to see if the user is typing a full name or not, but I'm actually not too concerned with any more complexity than I mentioned in the title. It's ok if an input like "GLba b" comes out positive.
I am setting text to textarea from textfield. It works perfectly. My challenge, however, is setting texts with spaces in-Between them. For example, what I observe is:Amount23 instead of: Amount 23. Is it possible to automatically create word space while setting texts?
1: 3D space. How do i define the space where i will make my world? Is there a certain point that i will define as 0,0,0 or is there some other way.
2: Camera positioning. When i have the 3D space, how to i make it so that the camera will show that what i want it to show. Lets say il define its lokatios 30,50,100 and direction is NW, then how to i make it so that is see the SW direction from the point 30,50,100?
I am attempting to create a 2d game that has a realistic space simulation. The map is supposed to be set so that you are looking from the top down. The problem I am having exists in my interaction between the sun and a planet. Simply put, the planet will only move in a single diagonal direction without ever changing direction. The formulas I am using are F=(G*M1*M2)/D^2 and A=F/M. The code below is simplified.
Things I have already tried: 1. Setting G to negative 2. changing the order of the subtraction in determining D 3. some weird pythagorean theorem thing someone suggested
I'm new to programming and I would just like to know what happens inside the memory once you run a java application. How do the memory allocate space for your objects or variables? Where does it start?does it start in memory location 1 first when I create my first variable or object? What is the use of variables and how is it used by the memory?Also if I create a variable named String s1 then I created another variable again named s1= "myString" Did I create a new object or I just edited the value of the s1 variable??
And if I create a variable int num1 = 10 then I created another variable int num1 = 12 did I create another one or I just edited the num1 variable?? Also how much memory would an object have? Does it depend on how many primitives objects like arrays or strings it have?Also I want to develop 3D games also, in the future is Java going to be great as I know machines in the future will have massive amounts of RAM and the JVM will be better...