PDA

Click to See Complete Forum and Search --> : Program that reads letters


emtmitalaitan
Nov 23rd, 2009, 04:37 AM
Well, i need to write program (school project) that reads letters and checks if you can form a sentence from the sentence / letters user has given to the program. (confusing?) Also after it has read it, it should check what letters are needed if it cant form it and what letters are spare if it can form it. sorry if its confusing, the sentence should be "learning is fun"



Heres the output what it should be like.. well at least something like this

welcome

give the sentence: learning is funny

sentence can be formed, the spare letters are n,y


ANY HELP WILL HELP, I have to get this done asap but i just don't have the skill for it yet. ( been tryin )


Edit: I know the basic int etc but cant make it work really, also i know scanner.. some of it.



Heres what i got so far..



i// MuokkaaTeksteja.java
//


import java.io.*;

class testia {

public static void main
( String [] args ) throws IOException {

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

String mjono;
int valinta;

System.out.println("Tervetuloa!");
System.out.println("Syötä lauseesi");
mjono = stdin.readLine();

do{
valikkoMetodi();
valinta = Integer.parseInt(stdin.readLine());

switch (valinta) {

case 1:
suurennaMetodi(mjono);
System.out.println(suurennaMetodi(mjono));
System.out.println();
break;

case 0:
break;

default: System.out.println("Väärä valinta");

}
} while (valinta != 0);
}

public static void valikkoMetodi() {
System.out.println("Valitse haluamasi toiminto: ");
System.out.println();
System.out.println("1) Tarkista voiko lauseestasi muodostaa Opiskelu on hauskaa");
System.out.println();
System.out.println("0) Lopeta ohjelma");
System.out.println();
}

public static String suurennaMetodi(String mjono) {

String mjonosuuri = null;

mjonosuuri = mjono.toUpperCase();

return mjonosuuri;
} // suurennaMetodi

public static String vaihdaJarjestysMetodi(String mjono) throws IOException {

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

String mjonokaannetty = null;

int pituus;
int i;
pituus = mjono.length();

for (mjono = stdin.readLine(), i = 0; i < pituus; i++) {
mjonokaannetty += Character.toString(mjono.charAt(pituus - i));
}

return mjonokaannetty;
}

}

emtmitalaitan
Nov 24th, 2009, 01:04 AM
C'mon, anyone? What the code in my previous post does is == it makes ur sentence to uppercase. and quits..

ComputerJy
Nov 24th, 2009, 04:10 AM
What is your question exactly?

leinad31
Nov 30th, 2009, 10:07 PM
if all sentences are derived from "learning is fun" then you can use regular expressions to check if user supplied sentence is similar, as well as for identifying excess characters.