211 Posted Topics
Re: /* Useful StringTokenizer */ [CODE]import java.util.*; import javax.swing.*; public class Date0 { public static void main(String args[]) { String text= JOptionPane.showInputDialog(null,"Type in the data in the format'02/14/2010'"); int ymd[] = new int[3]; StringTokenizer s = new StringTokenizer(text,"/"); for (int i=0; s.hasMoreTokens(); i++) ymd[i] = Integer.parseInt(s.nextToken()); text ="Your input is " … | |
Re: import java.io.*; import java.util.*; public class Profile { public static void main (String [] args) { String name="",user="",pass="",add=""; int ch=0, con=0; Scanner scn = new Scanner(System.in); while(true){ System.out.println("Enter your profile\n"); System.out.print("Name:"); name = scn.nextLine(); System.out.print("Username:"); user = scn.nextLine(); System.out.print("Address:"); pass = scn.nextLine(); while(true){ // only numeric allowed try{ System.out.print("Mobile:"); con … | |
Re: Do you mean [URL="http://www.roseindia.net/java/beginners/DelayExample.shtml"]the program [/URL]? | |
Re: An e-book: [URL="http://www.ebookee.net/Concepts-of-Programming-Languages-7th-Edition-_35213.html"]Concepts of Programming Languages (7th Edition) [/URL]by Robert W. Sebesta [url]http://www.ebookee.net/Concepts-of-Programming-Languages-7th-Edition-_35213.html[/url] is also helpful. | |
/* The following programs are written to guard the input. The input is requested as an non-negative integer.Is there other method to do so? */ /* Operation on DOS window: "PositiveInt1" receives a positive integer only. */ import java.util.*; public class PositiveInt1{ static int factorial(int n){ int fac=1; if ((n<0) … | |
Re: 1. The difference is in the name of the classes. 2. The Java language defines the signature (format) of the only main method in a class as public static void main(String args[]) {} meanwhile the name of the array of String may be given differently, e.g. public static void main(String … | |
/* In the following method, why the factorial goes wrong when n>12 ? */ static int factorial(int n){ int fac=1; if ((n<0) || (n>12)) return -1; for (int i=2; i<=n;i++) fac *=i; return fac; } | |
Re: An identifier is a symbol that establishes the identity of the one bearing it. [url]http://dict.cn/identifier[/url] It could also be a name of a constant. | |
Re: class Rock{ double weight; static int total=0; public Rock(double w){ setWeight(w); System.out.println("Rock " + ++total + " is created"); } void roll(){ weight *=1.2; } void setWeight(double d){ //成员方法 weight = d>0?d:1; } double getWeight( ){ return weight; } } public class RockTest{ public static void main(String args[]){ Rock rock[]= … | |
Re: Is your JLabel's instance on a background painted by the Graphics in AWT? If the background is made by the Graphics's object, there will be a trouble. The stuff in AWT is considered as heavyweighted while the stuff, such as JLabel's instance in swing, lightweighted. The heaveweighted stuff always "overwrites" … | |
Re: [code]import java.util.*; class cat{ String name; int age; double weight; String breed; boolean declawed; public cat(String s, int n, double d, String bs, boolean dec){ age=n; name = s; weight = d; breed = bs; declawed = dec; } public String getName(){ return name; } public int getAge(){ return age; … |
The End.