The Artima Developer Community
Sponsored Link

Java Answers Forum
Why doesn't this print?

4 replies on 1 page. Most recent reply: Mar 22, 2002 7:38 AM by Lynn Hollerman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
GunNam

Posts: 6
Nickname: gunnam
Registered: Mar, 2002

Why doesn't this print? Posted: Mar 22, 2002 1:33 AM
Reply to this message Reply
Advertisement
import java.util.*;
import java.awt.*;
import java.io.*;
import java.applet.*;
 
public class SuperMarket {
	String [] name = {"Jim","John","Joe","Richard","Paul","Michael","Peggy","Anne","Kathy","Jane","Chris","Noah","Shaina","Jordan","Matthew","Liza","Mila","Dianna","Jean","Andi","Julie","Jimmy"};
	int [] items = {5,5,5,3,3,3,4,4,3,3,4,5,5,4,3,4,3,5,3,3,6,4};
	double [] delay = {100.200,50,300,20,100,150,50,240,150,100,120,350,90,200,100.200,160,300,100,50,100};
 
  SuperMarket() {}
 
	public void run(){
	}
 
 
	public void print(int i) {
		System.out.println("\t" + name[i] + "\t" + items[i] + "\t" + delay[i]);
	}
	public static void main() {
		int i;
		SuperMarket Market = new SuperMarket();
 
		for(i=0; i<22; i++) Market.print(i);
	}
 
}


Yousuf

Posts: 19
Nickname: saeed
Registered: Mar, 2002

Re: Why doesn't this print? Posted: Mar 22, 2002 2:22 AM
Reply to this message Reply
replace <> to [] in print function

GunNam

Posts: 6
Nickname: gunnam
Registered: Mar, 2002

Re: Why doesn't this print? Posted: Mar 22, 2002 3:32 AM
Reply to this message Reply
I don't know why there are "<>" in my code. It must have happened during the copy/paste. Those ARE "[]" around the 'i's in the print() statement.

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Why doesn't this print? Posted: Mar 22, 2002 6:25 AM
Reply to this message Reply
Your main method is not the JVM is looking for. Change your main method as follows and then you can run your class. YOU missed to pass arguments to main method.
public static void main(String[] args)

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: Why doesn't this print? Posted: Mar 22, 2002 7:38 AM
Reply to this message Reply
I just copied and pasted your code. I had to change 3 things:

1) In your code, they're "[]" on your print line, not "<>", right? You might want to check those, as some other instances of "[]" came out fine.

2) "main()" needs to be "main(String[] args)"

3) Your "delay[]" array needs 2 more elements or you'll get a run-time error.

HTH!

Lynn.

Flat View: This topic has 4 replies on 1 page
Topic: TextListener for JTextArea ??? Previous Topic   Next Topic Topic: need help with a basic program

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use