2013-02-05, 19:29
#1
char bokstav = JOptionPane.showInputDialog(null, "Vilken bokstav vill du kontrollera?");
int count = 0;
for (int i=0; i < ord.length(); i++)
{
if (ord.charAt(i) == bokstav)
{
count++;
}
}
Scanner in = new Scanner(System.in);
int count = 0;
String sent = "fill me up";
System.out.println("Letter to search for:");
String slet = in.nextLine();
char letter= slet.charAt(0);
for(int x = 0; x < sent.length(); x++)
if(sent.charAt(x) == letter)
count++;
System.out.println(count + " " + letter + " was found");
case 5:
//Kontrollerar om bokstav finns i ordet
int antal;
String getChar = JOptionPane.showInputDialog("Mata in den bokstav du vill kontrollera: ");
for(int i = ord.length() -1; i>=0; i--)
{
if(getChar = ord.charAt(i))
{
antal++;
}
}
JOptionPaneshowMessageDialog(null, "Bokstaven " + getChar + " förekommer " + antal, " gånger i ordet!");
break;
case 5:
//Kontrollerar om bokstav finns i ordet
int antal = 0;
String getChar = JOptionPane.showInputDialog("Mata in den bokstav du vill kontrollera: ");
for(int i = ord.length() -1; i>=0; i--)
{
if(getChar.charAt(0) == ord.charAt(i))
{
antal++;
}
}
JOptionPane.showMessageDialog(null, "Bokstaven " + getChar + " förekommer " + antal + " gånger i ordet!");
case 5:
//Kontrollerar om bokstav finns i ordet
int antal;
String getChar = JOptionPane.showInputDialog("Mata in den bokstav du vill kontrollera: ");
for(int i = ord.length() -1; i>=0; i--)
{
if(getChar = ord.charAt(i))
{
antal++;
}
}
JOptionPaneshowMessageDialog(null, "Bokstaven " + getChar + " förekommer " + antal, " gånger i ordet!");
break;
Du måste vara medlem för att kunna kommentera