Friday, July 29, 2011

Assignment 8 #1,

Problem 6:
System.arraycopy(allSalaries,1,workerSalaries,0,7);

Problem 7:
a. It prints homer,Flanders,apu
b. change the method type to String [] and add return list;

Wednesday, July 27, 2011

P367 Number10

It is not legal to omit the pennyjar prefixes in the program.

Page 366 Problem 6.

line 21: x=3; Is incorrect because a non static variable cannot be referenced in a static method.
line 26: doIt(); Is incorrect because a non static method cannot be referenced inside of a static method.
Line 30: test.doIt(); Is incorrect because of the same reason as line 26.

Friday, July 15, 2011

Problem 7

Scanner stdIN = new Scanner(System.in);
String songs =
" 1. Bob Wow - Fresh Azimiz\n"+
"2. Weezer - Beverly Hills\n"+
"3. Dave Matthews Band - Crash Into me\n"+
"4. Sheryl Crow - Leaving Las Vegas\n";
String songNum;
int songIndex;
int eolIndex;
String song;
System.out.print("Enter song number: ");
songNum = stdIN.nextLine();
eolIndex=songNum.indexOf(songNum);
song=songNum.substring(eolIndex);
System.out.println(song);

Problem 6

public static void main(String[] args) {
// TODO code application logic here
Scanner stdIN= new Scanner(System.in);
String songs=
"1. Green Day- American Idiot\n"+
"2. Jesus Jones- Right Here\n"+
"3. Indigo Girls- Closer to Fine\n"+
"4. Peter Tosh - Equal Rights\n";
String searchText;
int foundIndex;
int count=0;
System.out.print("Enter Search text; ");
searchText=stdIN.nextLine();
if(songs.contains(searchText))
{
count++;
}
else
{
System.exit(0);
}
System.out.println("Number of ourrances of \"" +
searchText + "\" :"+count);
}
}

Tuesday, July 12, 2011

Problem # 5

for (i=2;i
{
product=num*i;
}

Problem # 3

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package p145number3;

/**
*
* @author chris.belsky
*/
public class P145number3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int count=0;
int sum=0;
int product=1;
do
{
count++;
product*=count;
sum+=count;
if(count == 5)
System.out.println("sum = " +sum);
System.out.println("Product = " + product);
}while(count<5) ;
}