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


ADVERTISEMENT

Program To Convert All Vowels To Capital Letter In A Sentence?

Jul 3, 2014

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');

[Code]...

View Replies View Related

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

Return Array Containing All Strings That Start With Letter A

May 13, 2014

Write a method that accepts an array of Strings.  The method must return an array containing all strings that start with the letter 'A'.  

There must be no 'null' values in the resulting array.  The resulting array may be of size zero.

I don't think I am returning ALL the strings that start with A, just the last one of the for loop. Does this look somewhat correct?

public String[] startsWithA(String[] strings) {
String startsWithA = strings[0];
for(int i = 0; i < strings.length; i++) {
if(strings[i].charAt(0) == 'A') {
startsWithA = strings[i];
}
return startsWithA;
}
}

View Replies View Related

Recursive Program To Change Two Four Letter Words Into Each Other?

Oct 28, 2014

SO for my project, we have to create a program where we input two four letter words, and using a list of words our teacher provided us and only changing one letter at a time, make the words match.For example, you input BALD and CALL and it would output BALD BALL CALLWe have to use recursion to do this, and I'm totally lost as to where to even begin.

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

Converting Strings To Bits / Bytes And Vice Versa

Feb 23, 2014

I have:

Java Code: String s = "111100100111011011000010110011101"; mh_sh_highlight_all('java');

I am trying to convert that to bits/bytes.

I need to make that into a series of bits with the same exact values..."1" = a 1 bit, and "0" = a 0 bit.

Remarkably, I haven't been able to find much on this sort of conversion - possibly I am just not searching with the right keywords? As typically, stackexchange or other parts of the web have the same question that I have, asked (and answered) by many others.

How do I go about doing this?

Furthermore, how would I go about saving this to a file - and are there already good "kinds" of files to save this into. If not, how do I go about making my "own" type of "file."

CONTEXT:

I've written a compression system. To keep things simple, I've been using a string to hold the 1s and 0s, so that debugging is simpler, and overall, everything is easier to write. Now, however, my algorithm is finished - and I'm moving on to create a GUI and a working system. This is the last step that I need for the non-GUI stuff (which I'm writing through javafx by the way - is this the right thing to use? I've been told that that is where people are moving towards. Away from swing).

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

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

Replace Correct Number Into Letter?

Mar 8, 2014

I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.

First, convert letter to number. Second, restore number to word.

Words list: a = 1, b = 2, f = 6 and k = 11.

I have word: "baafk"

So, for first step, it must be: "211611"

Number "211611" must be converted to "baafk".

But, I failed at second step.

Code I've tried:

public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);

[Code] .....

Result for converting to number: baafk = 211611 But, result for converting above number to letter: 211611 = bkfk

What do I miss here?

How to distinguish if 11 is for "aa" and for "k"? D

View Replies View Related

Number Sorting Having Prefix Letter

Dec 24, 2014

I had a list of some numbers having a prefix A like A12 , A55, A76 ,A111 ,A888, A88 ,A880 A111 , A11,A1

I need to sort this list so the result would be A1,A11,A12,A55,A76....

How to do this. Can I use arrays.sort method to achieve the same or any other way.

View Replies View Related

File Letter Counter Java

Nov 11, 2014

The point of this program is to search for a specific character in a text file. I want the program to find a character in the file "letterCounter.txt".

package lettercounter;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;

[code]....

View Replies View Related

Convert Integer To Letter Grades

Jan 31, 2014

/*This program will convert integer grades to letter grades and say how many A's, B's, C's, D's , F's do we have

public class DSlab3 {
private char LetterGrades;
private int IntegerGrades;
//default constructor
public DSlab3() {
LetterGrades =' ';
IntegerGrades = 0;

[Code] .....

View Replies View Related

Determining Letter Grade Of Students

Apr 14, 2014

The purpose of this project is to determine the letter grade of students. The program needs to accept two command line arguments:

The first being the name of a disk file that contains the names of students, and their test scores, separated by commas followed by one or more spaces. Each line in the file will contain scores for one student.

The second argument is the name of an output disk file. The program is supposed to create a new output disk file using that name.

The number of students in the input file is unknown during compile time. The name of input and output files could be anything and only known during run time. Additionally, the average scores, along with the minimum and maximum scores for each test are to be displayed in the console.

Calculation: Final Score = quiz1 * .10 + quiz2 * .10 + quiz3 * .10 + quiz4 * .10 + midi * .20 + midii * .15 + final * .25
Final Score >= 90% then letter grade is A, 80%-89% B, 70%-79% C, 60-69% D, <= 59% F

input_data.txt:

firstName lastName, 100, 90, 80, 100, 89, 99, 88
firstName lastName, 90, 90, 100, 100, 99, 100, 95
firstName lastName, 100, 90, 100, 70, 78, 78, 80
firstName lastName, 80, 90, 90, 100, 89, 99, 85
etc.

output_data.txt

firstName lastName: B
firstName lastName: A
firstName lastName: F
firstName lastName: B
firstName lastName: C

averages (to appear in console)
Q1 Q2 Q3 Q4 MidI MidII Final
Average: 82.25 80.38 82.85 83.88 81.38 84.13 78.63
Minimum: 60 54 38 62 62 60 50
Maximum: 100 90 100 100 99 100 95

Press ENTER to continue...

Here's what I have so far :

import static java.lang.System.out;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
public class LetterGrader {

[Code] .....

View Replies View Related

Random 3 Digit Letter No Duplicate

Nov 25, 2014

I need to know how many four letter strings I can generate that begin with the letter "v". Now I had been testing many ways to do this but anm stuck. I can generate a single line up only a certain amount. I need it to continue till it reaches the max number. So since it needs to always start with V i eliminated the need for four and only a 3 letter string.

package javaapplication4;
import java.util.Random;
public class JavaApplication4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Random r = new Random();
int c = r.nextInt(26)+ (byte)'a';

[code]...

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

Java - Replace Correct Number Into Letter

Mar 8, 2014

I'm trying to figure out the correct way to replace number into letter. In this case, I need two steps.

First, convert letter to number. Second, restore number to word.

Words list: a = 1, b = 2, f = 6 and k = 11.

I have word: "baafk"

So, for first step, it must be: "211611"

Number "211611" must be converted to "baafk".

But, I failed at second step.

Code I've tried:

public class str_number {
public static void main(String[] args){
String word = "baafk";
String number = word.replace("a", "1").replace("b","2").replace("f","6").replace("k","11");
System.out.println(word);

[Code] ...

Result for converting to number: baafk = 211611

But, result for converting above number to letter: 211611 = bkfk

How to distinguish if 11 is for "aa" and for "k"? Do you have any solutions or other ways for this case?

View Replies View Related

Input Letter - Output Whether Vowel Or Consonant?

Mar 16, 2015

I am trying to create a program for my class that requires the input of a letter and the output of whether or not it is a vowel or a consonant. I am using eclipse, it is giving me no errors, but when entering the letter i get an error in the console

import java.util.Scanner;
public class w0571505_a2a {
private static Scanner a;
public static void main(String[] args) {
// enter letter
System.out.println("Enter a Lowercase Letter");

[Code] .....

This is what i have...

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

Total Number Of Each Alphabetical Letter From A File

Nov 28, 2014

So far I've got it where the program is reading the file and returning

a:0
b:0
c:0
d:0
e:0
f:0
g:0
h:0
i:0
j:0
k:0
l:0
m:0
n:0
o:0
p:0
q:0
r:0
s:0
t:0
u:0
v:0
w:0
x:0
y:0
z:0

But I need it to print the letters and then the total amount of each character that is found in the file.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

[code]....

View Replies View Related

Program That Counts How Many Times A Letter Is Written

Sep 29, 2014

I can't get my code to print it like it's on the picture.

import javax.swing.JOptionPane;
import java.util.*;
public class BokstavTeller
{
public static void main( String[] args ) {
String input = JOptionPane.showInputDialog(

[Code] .....

View Replies View Related

Check If A Sentence From User Has Specific Letter?

May 1, 2014

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;

[Code] ....

View Replies View Related

Making Letter Bounce Off Of The Edges Of Frame

Jan 9, 2015

I am trying to make a letter bounce off of the edges of the frame, but im stuck .

Java Code:

import javax.swing.*;
import java.awt.*;
public class MainProgram extends JFrame{
public static void main(String[] args) {
// TODO Auto-generated method stub
MainProgram frm = new MainProgram();
frm.setTitle("Moving a letter");

[Code] ....

View Replies View Related

StringBuilder - Replacing Each Letter Without Reverse Tool

May 28, 2014

How can I replace each letter for example "abcde" to "edcba" with StringBuilder only and without the reverse tool. This is what I tried:

StringBuilder str=new StringBuilder("abcde");
int indexBegin=0;
int indexEnd=4;
for(int i=0;i<str.length();i++){
str.setCharAt(i, str.charAt(indexEnd));
indexEnd--;
}
System.out.println(str);

The output is:edcde with i understand why its wrong ,the last two letters already swap so it didnt take from the original str.

View Replies View Related

Check If Height Is A Letter Between A To J - If Statement Always False

Jun 22, 2014

Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in

String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E",
"e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"};
boolean trueHeight = true; // checks if height is a letter between a-j/A-J
do {
Terminal.printLine("Input height with letters A to J");

[Code] ...

View Replies View Related







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