Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Array help

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array help

    package lab5;
     
    public class ArrayFirst {
     
    public
    static void main(String[] args) {
     
    for (int i=0; i<args.length; ++i)
    System.out.println(args[i]);
    float[] a = {0.1f, 1.2f, 2.3f, 3.4f};
    System.out.println("length="+a.length);
     
    int n = a.length;
     
    	print("initial array a","a",a);
     
    	float[] b = new float[n]; // an array of n zeros
    	for (int i=0; i<n; ++i)
    		b[i] = a[i];
    	print("b = copy of a","b",b);
     
    	float[] c = new float[n];
    	for (int i=0; i<n; i++)
    		c[0] = a[3];
    		c[1] = a[2];
    		c[2] = a[1];
    		c[3] = a[0];
    	print("c = reverse of b","c",c);
     
    	float[] d = new float[n];
    	for (int i=0; i<n; i++)
    		d[i] = (float) Math.sin(c[i]);
    	print("d = sine of c","c",c);
     
    	float min = d[0];{
    		if (d[1]<min) min = d[1];
    		if (d[2]<min) min = d[2];
    		if (d[3]<min) min = d[3];
    		System.out.println("min = "+min);}
     
    	float max = d[0];{
    		if (d[1]>max) max = d[1];
    		if (d[2]>max) max = d[2];
    		if (d[3]>max) max = d[3];
    	System.out.println("max = "+max);}
     
    	float sum = d[0]+d[1]+d[2]+d[3];{
    		System.out.println("sum = "+sum);}
    }
     
    private static boolean isSorted(float[] a) {
    	System.out.println("a sorted?");
    	if (a[0] <= a[1] && a[1] <= a[2] && a[2] <= a[3]){
    		return true;
    	}else{
    		return false;
    }
    }
     
    private static void print(String heading, String aname, float[] a) {
    	System.out.println(heading);
    	for (int i=0; i<a.length; ++i)
    		System.out.println(aname+ "["+i+"] = "+a[i]);
    }
    }


    The isSorted portion of the program won't print.
    Last edited by mlan; February 27th, 2010 at 05:17 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Array help

    Hello mlan,

    It doesn't look like the isSorted method is called at any time?

    Note: I have moved this thread to the correct forum - Collections and Generics - Java Programming Forums
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array help

    Ohh!
    I didn't call it into the main of the program, yes?

Similar Threads

  1. [SOLVED] Create new Array from old Array
    By satory in forum Collections and Generics
    Replies: 1
    Last Post: February 24th, 2010, 11:44 AM
  2. Object array to int array?
    By rsala004 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2009, 04:09 AM
  3. Storing an array into an array
    By vluong in forum Collections and Generics
    Replies: 4
    Last Post: September 22nd, 2009, 02:14 PM