SI3TS DZ2 - Djordje Vukovic 08/0529
public class StringManipulation {
public StringManipulation(String input)
{
str = input;
}
private String str;
private int numberOfChars=0;
private int numberOfDigits=0;
public int GetNumberOfCharacters() { return numberOfChars; }
public int GetNumberOfDigits() {return numberOfDigits;}
public void SetString(String s)
{
str = s;
numberOfDigits=0;
numberOfChars=0;
}
public int ASCIIsum()
{
int zbir=0;
for(int i=0; i < str.length(); i++)
{
zbir+=(int)str.charAt(i);
}
return zbir;
}
public void Analyse()
{
int index = 0;
while(index<str.length())
{
if(Character.isDigit(str.charAt(index)))
{
numberOfDigits++;
}
if(Character.isLetter(str.charAt(index)))
{
numberOfChars++;
}
}
}
public boolean isDigit(int index)
{
for(int i=0; i<str.length(); i++)
{
if(i==index)
{
char c = str.charAt(i);
if(Character.isDigit(c))
{
return true;
}
else
{
return false;
}
}
}
return false;
}
public boolean isLetter(int index)
{
for(int i=0; i<str.length(); i++)
{
if(i==index)
{
char c = str.charAt(i);
if(Character.isLetter(c))
{
return true;
}
else
{
return false;
}
}
}
return false;
}
}
Previous by date: SI3TS Djordje Vukovic
Next by date: SI3TS DZ2 - Ivan Starcevic 08/0078
Previous by thread: SI3TS Djordje Vukovic Next by thread: SI3TS DZ2 - Ivan Starcevic 08/0078
Previous by thread: SI3TS Djordje Vukovic Next by thread: SI3TS DZ2 - Ivan Starcevic 08/0078