double d1; d1 = D.getDouble(); d1 = d1 * 2; D.setDouble(d1);
String s1, s2, s3; s1 = A.getString(); s2 = B.getString(); s3 = s1 + s2; C.setString(s3);
int i1, i2;
i1 = A.getInt();
i2 = B.getInt();
if (i1>i2)
{
C.setInt(i1);
}
else
{
C.setInt(i2);
}
String s1, s2; s1 = A.getString(); s2 = B.getString(); A.setString(s2); B.setString(s1);
String s1; s1 = A.getString(); s1 = s1.substring(0,s1.length()-3); A.setString(s1);
String s1;
int i1;
s1 = R.getString();
i1 = s1.indexof("A");
D.setInt(i1);
double value[];How do you construct one?
value = new double[300];How do you put a 6 into every entry of an integer (int) array. Assume that numElts contains the number of elements in the array.
int value[];
value = new int[100];
i = 0;
while(i<numElts)
{
value[i] = 6;
i = i+1;
}
How do you put a "Yes" into every entry of a
String array? Assume that last contains the final
index of the array that you want to set.
String value[];
value = new String[20];
i = 0;
while(i<=last)
{
value[i] = "Yes";
i = i+1;
}
See the 20 example problems and solutions from a previous handout.
Say there is a String s1:
public boolean action(Event e, Object obj)
{
if (e.target==initializeA) {
{
s1 = A.getString();
A.setString("");
return true;
}
return true;
}
Say we have String trfull, trfirst, trlast, trmiddle;:
public boolean action(Event e, Object obj)
{
if (e.target==EX) {
{
trfull = TR.getString();
trfirst = trfull.substring(0,1);
trmiddle = trfull.substring(1,trfull.length()-1);
trlast = trfull.substring(trfull.length()-1,trfull.length());
trfull = trlast + trmiddle + trfirst;
TR.setString(trfull);
return true;
}
return true;
}
Assume we have a double rsum and an int i
public boolean action(Event e, Object obj)
{
if (e.target==plus) {
{
rsum = 0.0;
i = 0;
while(i<=9)
{
rsum = rsum + R[i];
i = i+1;
}
SUM.setDouble(rsum);
return true;
}
return true;
}
Assume we have a String afull, afront, aback and int index
public boolean action(Event e, Object obj)
{
if (e.target==del) {
{
index = B.getInt();
afull = A.getString();
afront = afull.substring(0,pos);
aback = afull.substring(pos+1,afull.length());
afull = afront+aback;
A.setString(afull);
return true;
}
return true;
}
public String strInTitle(String test)
{
if (title.indexof(test) == -1)
{
return "No";
}
else
{
return "Yes";
}
}