Taking String And Printing Only The Digits?

Apr 26, 2015

This is the code that I have so far, It will only print out the digit if it is entered first..How to I get it to print out all digits? and I am getting an error that the c is not initialized

import java.util.*;
//Write a program that prompts the user for some text. Output only the digits in that text. Hint: Use a loop and the Character.isDigit method.
public class Q1
{

[Code].....

View Replies


ADVERTISEMENT

Taking String That Contain Sentence And Reversing The Words

Sep 5, 2014

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.

View Replies View Related

Simple If Statement Taking A String Input Doesn't Work

Jun 6, 2014

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
if (input == "next") {
System.out.print("good Job!");
}
else {
System.out.println("Why ?");
}

//If I type in next it prints out "Why ?" instead of "Good Job!" - Why though ?

View Replies View Related

String Only Contains Digits And Dash

Jan 14, 2014

How can i make a method that makes sure that a String only contains digits and "-" (dash) ... (I want to make sure that the method can see if the user has written in an okay telephone number...)

This is what I've done this far.. But the method retuns false if you type - or +

static public boolean telephoneValidation(JTextField tf) {
boolean svar;
try {
Integer.parseInt(tf.getText());
svar = true;
}
catch(NumberFormatException fel)

[code]...

View Replies View Related

User To Input Integer And Then Outputs Both Individual Digits Of Number And Sum Of Digits

Feb 2, 2015

Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.

import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;

[Code] ....

View Replies View Related

Printing Out String Out Of Index?

Jan 24, 2014

I am writing a Java permutation program, it takes in N and k and gives k amount of combinations based on N length.

That portion works, but the portion I have that does not work is when k is greater then 1, the array is then then printing strings out of index.

The perm algorithm ends on index - 1 for moving characters but then I push all those characters into an Array List, I would think I could print them off however I want from there but that is not the case. I'll include the minimum amount of code possible.

//permString = 1234 or something, it doesn't matter
//Use Case N = 4 k = 3, prints out 123,124,132,134 ect
//Use Case N = 4 k = 2, error index out of range but only on the printing function; the perm function doesn't take k and
//is based on length
//the "" is just an empty string
permNow("", permString);
}

[code].....

View Replies View Related

Code Not Printing String Literal

Sep 18, 2014

I need to use print not println to declare stuff and I need to have string literals I think that's /n. Now when I compile it just shows row1, row2 ect. Why does it work like that?

public class art {
public static void main(String[] args) {
//local variables
String row1= "***********************";
String row2= "** *** *** **";
String row3= "** ***** ***** **";

[Code] ...

View Replies View Related

String Inputs And Outputs - Printing Information To Console

Mar 22, 2014

Write an application that asks the user to enter his/her first name, last name, birthday, and where you born (all fields type String) and prints their information to the console. Use the techniques discuss in class. The data must be encapsulated. The program must be coded in Notpad++ and compiled in the Command Prompt.

Output should be like this:

Welcome!

What is your first name? Carlos

What is your last name? De La Torre

When is your birthday? 08/12/1979

Where did you born? Puerto Rico

First Name: Carlos

Last Name: De La Torre

Birthday : 08/12/1979

Born in : Puerto Rico

This is what I have so far :

package myinfo;
import java.util.Scanner;

public class MyInfo {
private String name;
private String lastName;
private String birthday;
private String birthPlace;

[Code] ....

View Replies View Related

Converting Long Values To String - BufferedWriter Not Printing Desired Results

Apr 20, 2014

Currently, my program converts Long values to String. And when I test it out, it do print out the correct output. However, when the converted String value is passed over to be written in a text file, it seems that BufferedWriter isn't printing out the outcome that it's supposed to be.

saltVs = Long.toString(saltV);
System.out.print(saltVs); //will print out 79723172

Now the problem is here...It only prints out the last digit of the String value (instead of 79723172).

Here is my FileWriter/BufferedWriter part.

Why is that when I run my program using command prompt, it prints out the output that I wanted, but however when it comes to writing to the file, it doesn't come out right.

View Replies View Related

Taking Out Min And Max From Array

Apr 11, 2014

This piece of code is giving me the most trouble as I cannot convert the self defined class (Fraction) into int in order to store the elements in the variable (max). What is the best way to go about grabbing the next element and storing it in max and compare it to the previous to get the highest and lowest value?

System.out.println("Enter numerator / denominator");
frak[0] = new Fraction(keyb.nextInt(), keyb.nextInt());
frak[0] = max;
for (int i = 1; i < frak.length; i++){ // starting from array element 1
System.out.println("Enter numerator / denominator");
frak[i] = new Fraction(keyb.nextInt(), keyb.nextInt());
if (max > frak[i]){
}

View Replies View Related

Call To OS From App Taking 10 Mins On Certain PC

Jul 9, 2014

I have written a java app that's been working for a few years now and the client is very satisfied. However, a certain user has been experiencing a problem where the app runs fine BUT whenever it interacts with the OS (Win7 in this case), it takes ~10 mins to respond. Actions include, for example, exporting the currently displayed JTable to a CSV file or making an OS call to open up MS Word, etc.

I copied the users version of the app onto my platform (win 8.1) and tested it on winXP too with no problems which points towards an issue on the users particular PC. Furthermore, it used to run on the users PC fine until something (??) happened.

I've tried the following so far:-

1. looked at System restore to check anything new installed - nothing obvious
2. disabling anti virus - problem still occurs
3. monitoring JVM process time using Task Manager - little CPU time seems to be utilised (=> no loop etc)

I'll try :-

1. using JvisualVM - although I don't think this will show me what's going on with the OS
2. excluding the JVM and the app from all anti malware

Any app or something that shows interaction with the OS so I can trace what might be intercepting the call from my app to the OS?

View Replies View Related

Scanner Taking Input Twice

Oct 29, 2014

I have a small bug in my program. The user is asked what person(s) information they want to access but lets say they want captain they must enter "captain" twice. I think it will make more sense to you with the code. I have searched all over to see what is causing the bug but still have found no resolution. I even tried making two different scanners but that didn't work either.

I know the while loop (line 16) I am using is causing the bug because it works fine without that but then I cannot validate the input.

package myproject;
import java.util.Scanner;
public class Enterprise {
public static void main (String[]args){
String userInput;

[Code]......

View Replies View Related

Taking In User Input While Encapsulating

Oct 25, 2014

What I have so far are two classes, Movie class and MovieTestDrive class. I've to get the title, genre and ratings for movies and then put them into an array and call the playIt() method.

I would like to create a for loop to iterate three times for three instances of the Movie class but I don't know how to do it.

When I try to run the code, it won't work and I don't know if this is because I have Scanner running incorrectly whilst encapsulating my data. What I have so far:

class Movie {
// Create instance variables for the Movie class.
private String title;
private String genre;
private int rating;
// Use getters and setters to set and display the variables.

[Code] .....

View Replies View Related

Standalone Taking So Much Time Than Web Application

Oct 29, 2014

I am working on a web-application where i have a functionality which generates reports based on the data from DB. for small amount of data its working nice if the data is huge its taking more time. to avoid this problem i developed a standalone batch where i generated the jar file for the sources in web-application and made a call to the appropriate methods.

But my problem is if web-application takes 10 secs to generate the report but in the case of standalone its taking nearly 3-5 mins to generate the same report. i didn't do much of the changes in code just using the same code as web-application

I am using tomcat 6 application server to run the web-application for standalone using batch commands.....

View Replies View Related

Inventory Program - Taking Input For ArrayList

Feb 3, 2014

I am stumped on a coding project I am working on. I am making an inventory program with predefined values for the items. I am not sure how to iterate through my arrayList, and allow the user to input the "number sold."

I have made an arrayList and populated it using the add(), but I am not sure if it is working correctly. This is my inventoryItem class :

package inventory;
import java.text.DecimalFormat;
public class inventoryItm {
String itemName;
double unitPrice;
int numberSold;

[Code] .....

View Replies View Related

Anomaly While Using Scanner Class For Taking Inputs

Feb 1, 2015

There is a problem that I am facing while using the Scanner class for taking inputs from the user. Suppose if I need to take an integer and a String input from the user, and I take the integer input first then the place where the user has to input the String skips and the variable shows a "" nothing on printing it. Suppose in this code snippet

import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
System.out.println("Enter a word");
String str = sc.nextLine();
System.out.println("Enter integer is " + n);
System.out.println("Entered statement is " + str);
}
}

The output is
Enter a number
13
Enter a word
Enter integer is 13
Entered statement is

I need to know why this happens and how should I avoid it. I've seen that taking the String input first solves the issue but while taking the input in a loop to populate a database the program only lets the user enter the first statement and the following statements are skipped.

View Replies View Related

Taking Information From Google Doc And Storing To Be Able To Print Later

Jan 20, 2015

I've looking for information on taking a range of data from a google sheet such as the one below.

JavaGroupCat.png

The function that i'm trying to accomplish is allowing a user to run the program and input their 5-digit Unique - ID. After inputting their 5-Digit ID the program will take that input, and check whether or not that ID is present on the spreadsheet.

Ex: (Using the numbers from above) I type in : "89504" then (I would want the program to spit out if the ID is on the sheet).
(89504 appears on the sheet) So i would want it to print out something like "ID is found on list "Cat".
Associated named include: "Phil Roberts".

I tried, with my limited knowledge, to create what I have described above.

import java.io.*;
import java.util.*;
public class SwitchesTwo
{
public static void main(String args[]) {
System.out.println("Welcome to the ID # Checker");
System.out.println("Enter the ID of the person you are trying to verify");

[Code].....

The issue I have with the mock-up above is the fact that I have to manually add in every individual name and ID. I would much rather write code that would allow it to update as I update the spreadsheet. Therefore, no need for 800+ cases. (theres around 800 ID numbers for this project)

In a perfect world, the code would be something like "Take info from cells C5 - C2000 and store as string array" (I think array would work.) while also doing the same with B5 - B2000.

View Replies View Related

Swing/AWT/SWT :: Track Down Why SetViewPortView On A JScrollPane Is Taking So Long

Apr 27, 2014

I've built up an unreasonably large and unreasonably complicated JPanel. Unfortunately, when I use setViewportView to add it to a JScrollPane, a get an extended UI freeze—that operation takes several seconds. I'm trying to figure out what's taking so long. I've tried some fairly extreme things, like overriding the paintComponent, PaintComponents, paintChildren, paint, repaint, validate, revalidate, and validateTree methods in the panel with no-ops to try to figure out what's taking so long, but to no avail. I've tried validating the JPanel before adding it, but that has no effect. If I override the addImpl method of the scroll pane, that makes things quick, but it doesn't really narrow things down much.

View Replies View Related

Taking Object As Input - Instanceof Keyword Test

Feb 7, 2014

I am trying to test the instanceof keyword. To do this, I've made a method with a simple logical test like so:

Java Code:

Vehicle vehicle1 = new Vehicle();
public void Type(){
if (vehicle1 instanceof Vehicle) {
System.out.println("Type = Vehicle");
}
else if (vehicle1 instanceof Car) {
System.out.println("Type = Car");
}
else if (vehicle1 instanceof Truck) {
System.out.println("Type = Truck");
}
}
} mh_sh_highlight_all('java');

I wanted to try implementing it into the class definitions for Vehicle, then extend that to Car and Truck, but I'm not sure how to use this test in a general case.

The only way this method works is if I set the test to specifically accept a specific object as a parameter.

I want to test multiple objects, but I'm not really sure how else to do this without simply copy-pasting the logical test multiple times and changing the respective objects that are used as parameters.

View Replies View Related

Swing/AWT/SWT :: Taking Inputs Based On Previous User Input

Jun 7, 2014

I'm developing a Swing application for the first time. To test my application, I have currently hardcoded some text labels and fields in a JPanel, so that a user can enter input details for a maximum of 3 segments. But this limits the maximum number of segments to 3. However, the requirement is that when the user enters the number of segments (could be greater than 3 as well), corresponding number of input sets need to be taken.

Screenshot attached, with values entered.

Basically I want to know how I should go about taking the inputs from the user.

View Replies View Related

Taking Range Of Names In Array And Outputting Them Alphabetically - OutOfBoundsException

Apr 24, 2014

At the moment I am studying it and the problem is Taking a range of names in an array and outputting them alphabetically, But for some reason I get an outOfBoundsException. And its starting to get to me. How to put the code in

import java.util.Scanner;
import java.util.Arrays;

public class lab241 {
public static void main(String[] args) {
Scanner kb= new Scanner(System.in);
String[ ] names = new String[4];

names[0]= ("Horatio");
names[1]= ("Anatoly");
names[3]= ("Evelyn");
names[4]= ("Anna");
Arrays.sort(names);
for(String N: names){

System.out.println(N);

View Replies View Related

JSF :: Primefaces Live Scrolling Taking Long Time With Large Dataset

Feb 21, 2014

I have a primefaces datatable with about 52000 records to be fetched.Since it is a large dataset,i tried using live scrolling feature of primefaces with scroll rows equal to 20.THe number of columns is 53.The table also has filtering and sorting feature on its each column.Still i am not satisfied with the performance of the table.It takes about 15 secs for the page to load,worst thing is that it takes about 65 secs for the next set of 20 records to be loaded on reaching the end of scrolling.

Just for testing i reduced the total number of records to 25000 and the preformance improves with scroll time of 29 secs.I am really not able to understand why it is taking this much time when i am displaying only 20 records at a time.The total number of records should not have affected the performance.

My JSF code snippet

<p:dataTable id="arcRecList" var="data"
value="#{archivedRecordBean.archiveItems}"
tableStyle="table-layout:auto; width:80%;" styleClass="datatable"
scrollable="true" scrollWidth="84%" scrollHeight="69%"
columnClasses="columnwidth" liveScroll="true" scrollRows="20"
filteredValue="#{archivedRecordBean.filteredArchiveItems}">

[Code] ....

View Replies View Related

Insert Break Line To Text Message On Hitting Enter By Taking Its ASCII Value

Mar 2, 2014

I need to insert a break line to a text message on hitting enter by taking its ascii value i.e 10.I have used node.insert commands.I have tried using node.insertAttribute and node.insertChars but is not working ....

View Replies View Related

How To Sum Digits

Jan 30, 2015

I have to seperate a number 9876 to 6 7 8 9, to 9 8 7 6. I need to know how to sum the digits. I have gotten to this point ::

import java.util.*;
public class week4program
{
static Scanner console = new Scanner (System.in);
public static void main(String[] args) {
int num1;
int digit;
int sum = 0;

[code]....

To this point its gives me the seperate integers. OK but how do I get the variable integers into seperate containers and then add them up?My assignment is to do that, and what I have above gets me to where I have seperate digits, but how do I catch them into seperate entities to be added to a sum?

View Replies View Related

Sum Of Odd Digits Of Input

Oct 14, 2014

I have it so it gives me the sum of any digit, i just cant figure out how to get only the odd digits to add up. for example if I were to type 123. The odd numbers = 4 but using this program i get 6

class SumOfDigits {
public static void main(String args[]) {
int sum = 0;
System.out.println("Enter multi digit number:");

[Code] ....

View Replies View Related

Sum Of Digits In Java

Feb 3, 2014

import java.util.Scanner;
public class CubesSum { 
public static void main (String [] args){
int input;
System.out.println("Enter a positive integer:");
Scanner in = new Scanner(System.in);
input = in.nextInt();

As you can see I'm using a while loop. For part B which is to modify to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits. So for example, 371 = 3³+7³+1³. How to do it? I need to wrap a for loop around my while loop...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved