How To Print 5th Letter Of A String

Nov 11, 2014

So if I wanted to tell the user that the fifth letter they entered is "____" how would I do that.

I am prompting the user to enter a word and then displaying the length of the String. Now I want to display to the user what the fifth letter of the String they entered is.

import java.util.Scanner;
public class StringPractice
{
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
String word;
int lenght;

[Code] ....

View Replies


ADVERTISEMENT

How To Get 1st Letter Of Input (String) And Compare It To Single Letter Before Insert To DB

Apr 15, 2014

Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database

code = "A"001
name ="Angela"
= success this will inserted into database

else

code ="B"002
name="Angela"
=failed this will not inserted into database

else

code="A"003
name="Andy"
=success still accepts the input cause they have diff code number

What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?

View Replies View Related

How To Use Nested Loops To Print Out A Letter Pattern Wraps From Z

Jan 6, 2015

//method class
import static java.lang.System.*;
public class TriangleFive
{
private char letter;
private int amount;
public TriangleFive()
{

[Code]...

View Replies View Related

Switch Statement That Decides What Range To Print Based On Letter Grade Input

Nov 1, 2014

Alright so I wrote a switch statement that decides what range to print based on the letter grade input.

import java.util.Scanner;
public class SwitchPractice
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);

[code]...

It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.

View Replies View Related

String Of Words - Getting First Letter From Each Word?

Mar 26, 2014

If I have a string of words and want to get a letter from each word (let's say the first), how do I code for anything past two?

For example, if I have North Atlantic Treaty Organization and I want to convert it to NATO I would do something like:

charAt(0) for N
charAt(x + 1) for A

But what do I do for anything past the second string? If I do charAt(x ++ 1) I get an error.

View Replies View Related

Convert The First Letter Of Every Word In A String To Uppercase?

Sep 20, 2014

I'm trying to convert the first letter of every word in a String to uppercase. I've managed to isolate the first letter of every word and then make it uppercase but I don't know how to replace it.

public static StringBuffer makeUpperCase(){
String str = String.valueOf(input2);
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == ' '){
char var = str.charAt(i + 1);
var = Character.toUpperCase(var);
System.out.println(var);
}
}

View Replies View Related

How To Find Multiple Instances Of Same Letter In A Single String

Nov 29, 2014

I have got a pretty good framework working for my hangman game so far, however I am quite stumped on how to find multiple instances of the same letter in a single string. I am using indexOf to find the instance of a character in a string, but it only returns the first instance. So if the words(s) contain(s) multiple instances it doesn't register the rest.

public static void main(String[] args) {
String word = "crazy horse";
String answer="";
String space=" ";
String dash="-";

[code]....

View Replies View Related

Strings - Change Every Capital Letter Into Small Letter And Vise Versa

Oct 22, 2014

I have a problem with functions connected to strings.

I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.

lowercase= "abcde...z" and

uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.

There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".

How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.

View Replies View Related

Capitalize Method - Return String With First Letter In Uppercase And All Other In Lowercase

May 19, 2015

I'm trying to create a private method called capitalize() which takes String nameModel in any uppercase/lowercase combination and returns it with the first letter uppercased and all other lowercased. E.g. "stePHeN" returns "Stephen" . This is what I've written so far:

private String makePrettyString(String modelName) {
if (modelName ==null) {
return null;
}else if (modelName =="") {
return "";
} else{
return modelName.substring(0,1).toUpperCase() + modelName.substring(1).toLowerCase();
}
}

Unfortunately it doesn't work and it still returning me the String modelName in its original uppercase/lowercase combination.

View Replies View Related

Take Replacement String Entered By User And Print Out New String

May 22, 2014

I'm having trouble with the last few lines of the code. It's supposed to take a replacement string entered by the user and print out the new string. For some reason it's now allowing me to enter a replacement string

import java.util.Scanner;
public class Project02 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a long string: ");
String lString = keyboard.nextLine();

[Code] ....

Output:

Enter a long string: the quick brown fox jumped over the lazy dog
Enter a substring: jumped
Length of your string: 44
Length of your substring: 6
Starting position of your substring in string: 20
String before your substring: the quick brown fox
String after your substring: over the lazy dog
Enter a position between 0 and 43: 18
The character at position 18 is x

Enter a replacement string: Your new string is: the quick brown fox over the lazy dog <------ isn't taking user input

View Replies View Related

Program That Continuously Asks For Alphabet Letter And Stops When Non-Alphabet Letter Entered

Oct 8, 2014

Write a program that continuously asks for an alphabet letter, and stops when a non-alphabet letter is entered. Then output the number of upper case letters, lower case letters, and vowels entered ....

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

How To Print String Only Five Times

Feb 11, 2015

I can't figure out how to print this string only five times. I tried to use the * operator, but that doesn't work with strings apparently, unles i'm not importing correctly.
 
import java.lang.String;
public class Looparray
{
public static void main(String args[] {
for (String myStr= "Hello there!";;) {
System.out.print (myStr);
System.out.print("
");
}
}
}

View Replies View Related

Print Pyramid String Error

Nov 18, 2014

I'm having a small error with my code, it is getting rid of the first letter of the string after the first line printed.

import java.util.*;
public class PrintPyramidName {
public static void main(String[] args) {
System.out.println("What is your name?");
Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related

Why Print Char 0 (zero) plus String Does Not Work

Apr 3, 2015

I have a simple doubt. I was studying and create some code to check the result and I found out a strange situation.
 
Whats wrong with this code? Why it does not print anything?
 
char = 0; //integer value
System.out.println( c +" String ");
 
and why this next works very well?
 
char = 1; //integer value
System.out.println( c +" String ");
 
I know that char is stored as a positive integer and assign with 0 is different of assign with '0'.

View Replies View Related

Print String From Starting Character Given By User

Jul 14, 2014

Now I am doing dictionary app using files..

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..

View Replies View Related

Read Through A String / Count How Many Vowels There Are And Print Out When Detected

Sep 15, 2014

So I need to write a program that reads through a String and counts how many vowels there are and prints them out as it finds them. This is what I have so far:

if (vowel == 'a' || vowel =='e' || vowel =='i' || vowel == 'o' || vowel == 'u'){
numberOfVowels++;
}

The problem is that I can't figure out how to print out the character once it detects it as a vowel.

View Replies View Related

Writing To Text File - Print String On One Line

Oct 19, 2014

I am writing to a text file via user input and it is saving all the user input to the file but it is just printing one word per line. I would like it to print the string on one line and print the next string on the next line upon them hitting enter.

public void textFile() {
Scanner reader = new Scanner(System.in);
System.out.println("Enter file name: ");
String fileName = reader.next();
File f = new File(fileName);
PrintWriter p = null;

[Code] ....

View Replies View Related

Store String Input In Array And Print In Reverse Order

Apr 5, 2014

I have a college question ask me to write a class StringRevert which does the following:

-prompting user for an interger n
-creating an array of n string
-repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array)
-print the string from array in reverse order, from last enter to first enter.
-assume user always supplie correct input

This is what I've done so far but how to get it working.

import java.util.Scanner;
public class StringRevert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter value of n: ");
int n1 = in.nextInt();
String[] n = new String[n1];

[Code] ....

View Replies View Related

Search For A String In Large Text File Of 1 GB Size And Print Line When Match Found

Feb 18, 2014

I have a large text file of 1 GB size. I need to print the line when a matching word is found in a particular line. Below is the code I am using. But if there are many lines that has the matching word, it's taking lot of time. Any solution to print the lines much faster.

Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line.contains("xyz")) {
System.out.println(line);
}
}

View Replies View Related

Convert 2D Array To String Using ToString To Print Array

Apr 19, 2015

Trying to convert 2D array to String using toString() to be able to print the array but when I try to use it I just get the memory location

public class Forest
{
private int h;
private int w;
private double p = 0.7;
private int[][] f;
Forest(int w, int h)

[code]....

View Replies View Related

New Method Array To String Or Just Print As Array?

Feb 20, 2014

I just tried to fill an array with some numbers, calculated by a other function.I just tried to print this array as array, but it doesnt work. Maybe its just about the main method.

public static void main(String[] args) {
ggT(5);
}
 
public static int ggT(int a, int b) {
 
while(a!=b){
if(a>b) {
a=a-b;
} else {
b=b-a;
}
}
return a;
 
[code]....

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Three Letter Acronym

May 20, 2014

import javax.swing.*;
public class ThreeLetterAcronym{
public static void main(String[] args){
String phrase = "";
String firstWord = "";

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Inputting One Letter Into JTextField

Mar 9, 2014

I'm writing a java program in eclipse of a tic-tac-toe game. I have to create it using JTextField's only I'm having trouble where the JTextField will only accept one letter and will only accept X and O is there any particular way to do this I started off with this piece of code

String text=tf1.getText();
if(text.length()>1) {
System.out.println("this is not allowed");
tf1.setText("");

But it doesn't work so is there something I'm missing....

View Replies View Related







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