Java 2D array program help please?

Hi - I'm teaching computer science to myself (java, using jGRASP) using some websites online, and one of the activities I have to do is to make an "image smoother" program.
I just started learning about 2D array, and I think I get what it is (based on what I know of 1D arrays), but I have no clue how to do this activity.
This is what the description says:
"A grey-level image is sometimes stores as a list of int values. The values represent the intensity of light as discrete positions in the image.
An image may be smoothed by replacing each element with the average of the element's neighboring elements.
Say that the original values are in the 2D array "image". Compute the smoothed array by doing this: each value 'smooth[r][c]' is the average of nine values:
image [r-1][c-1], image [r-1][c ], image [r-1][c+1],
image [r ][c-1], image [r ][c ], image [r ][c+1],
image [r+1][c-1], image [r+1][c ], image [r+1][c+1].
Assume that the image is recangular, that is, all rows have the same number of locations. Use the interger arithmetic for this so that the values in 'smooth' are integers".
and this is what the website gives me along with the description above:
import java.io.*;
class Smooth
public static void main (String [] args) throws IOException
int [][] image = {{0,0,0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,5,5,5,5,5,5,5,5,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0}};
//assume a rectangular image
int[][] smooth = new int [image.length][image[0].length];
//compute the smoothed value for
//non-edge locations in the image
for (int row=1; row<image.length-1; row++)
for (int col=1; col<image[row].length-1; col++)
smooth[row][col] = sum/9;
//write out the input
//write out the result
"The edges of the image are a problem because only some of the nine values that go into the average exist. There are various ways to deal with this problem:
1. Easy (shown above): Leave all the edge locations in the smoothed image to zero. Only inside locations get an averaged value from the image.
2. Harder: Copy values at edge locations directly to the smoothed image without change.
3. Hard: For each location in the image, average together only those of the nine values that exist. This calls for some fairy tricky if statements, or a tricky set of for statements inside the outer two.
Here is a sample run of the hard solution:
c:\>java ImageSmooth
input:
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 5 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
output:
0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 1 1 0 0
0 1 2 3 3 3 3 3 3 2 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 3 5 5 5 5 5 5 3 1 0
0 1 2 3 3 3 3 3 3 2 1 0
0 0 1 1 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0
c:\>"
OKAY that was very long, but I'm a beginner to java, especially to 2D arrays. If anyone could help me with this step-by-step, I would greatly appreciate it! Thank you very much in advance!

larissa. wrote:
I did try, but I have no clue where to start from. That's why I asked if someone could help me with this step by step...regardless, our track record for helping folks who state they are "completely lost" or "don't have a clue" is poor to dismal as there is only so much a forum can do in this situation. We can't put knowledge in your head; only you can do that. Often the best we can do is to point you to the most basic tutorials online and suggest that you start reading.
That being said, perhaps we can help you if you have some basic knowledge here, enough to understand what we are suggesting, and perseverance. The first thing you need to do is to try to create this on your own as best you can, then come back with your code and with specific questions (not the "I'm completely lost" kind) that are answerable in the limited format of a Java forum. By posting your code, we can have a better idea of just where you're making bad assumptions or what Java subjects you need to read up on in the tutorials.

Similar Messages

  • I can't open adobe illustrator CS6 -Java  issues, can anyone help please

    I can't open adobe illustrator CS6 - I downloaded latest java for OSx, and it still directs me to download Java 6.  Can anyone help please, thanks

    Java for OS X 2014-001 10.7 or later

  • Basic blackjack program - help please

    can soemone please still me if this will work?
    this will become a VERY rudimentary blackjack program
    meaning there is no AI.
    this is how i wanted
    You got a "card"
    You got a "card"
    your score is:
    would you like to hit or stay?
    and then if it hits it tells u the dealers score
    then it keeps on doing the same thing..like
    you got a..
    your score is...
    hit or stay?
    and of course im trying to add to ask the user if they want A to be 1 or 11 (which i have but dont know how to incorporate)
    sorry this is my second day learning java so be easy on me.
    no double down or splits or betting is required.
    this is basically a skeleton that im having trouble using
    but i have to use the given randomGenerator
    can somone help me organize this or help me add codes to do this?
    import java.io.*;
    import java.util.*;
    public class blackjack
        public static void main ( String [] args )
            ConsoleReader console = new ConsoleReader( System.in );
            int uscore = ucard1 + ucard2;
            int dscore = dcard1 + dcard2;
            int dcard1; // dealer card1
            int dcard2; // dealer card2
            int dcard3; // dealer card3
            int dcard4; // dealer card4
            int dcard5; // dealer card5
            int ucard1; // user card1
            int ucard2; // user card2
            int ucard3; // user card3
            int ucard4; // user card4
            int ucard5; // user card5
            int hit = 1;
            while (hit == 1)
            Random generator = new Random ();
            int diamonds = 1 + generator.nextInt( 13 );
            int spades = 1 + generator.nextInt( 13 ); 
            int hearts = 1 + generator.nextInt( 13 ); 
            int clubs = 1 + generator.nextInt( 13 ); 
            System.out.println ("Welcome to the Blackjack Game");
            switch ( dcard )
               case 1:   return "Ace";
               case 2:   return "2";
               case 3:   return "3";
               case 4:   return "4";
               case 5:   return "5";
               case 6:   return "6";
               case 7:   return "7";
               case 8:   return "8";
               case 9:   return "9";
               case 10:  return "10";
               case 11:  return "Jack";
               case 12:  return "Queen";
               case 13:  return "King";
            switch ( ucard )
               case 1:   return "Ace";
               case 2:   return "2";
               case 3:   return "3";
               case 4:   return "4";
               case 5:   return "5";
               case 6:   return "6";
               case 7:   return "7";
               case 8:   return "8";
               case 9:   return "9";
               case 10:  return "10";
               case 11:  return "Jack";
               case 12:  return "Queen";
               case 13:  return "King";
           if ( dcard1 + dcard2  == 21) {
                System.out.println("Dealer has Blackjack.  Dealer wins.");
               return false;
          if (  ucard1 + ucard2   == 21) {
              System.out.println("You have Blackjack.  You win.");
               return true;
            System.out.println(" You got "+ ucard1 +"  ");
            System.out.println(" You got "+ ucard2 +"  ");
            if ( value2 == case 1 )
                System.out.println("Would you like your A to be 1 or 11?")
            System.out.println("Your score is " + uscore + ":");
            System.out.println("To hit press 1 and to stay press 2");
            hit = 0;
            hit = console.readInt();
            if ( hit =  1 )
                System.out.println("You got + ucard3 + ")
            System.out.println("Your score is " + uscore + ":");
            System.out.println("To hit press 1 and to stay press 2");
            hit = 0;
            hit = console.readInt();
                System.out.println("You got + ucard4 + ")
            System.out.println("Your score is " + uscore + ":");
            System.out.println("To hit press 1 and to stay press 2");
            hit = 0;
            hit = console.readInt();
            System.out.println("You got + ucard5 + ");
            System.out.println("Your score is " + uscore + ":");
            System.out.println("To hit press 1 and to stay press 2");
            hit = 0;
            hit = console.readInt();
            if (cont = 2);
            System.out.println("Dealer's score is + "dscore" + :");
            System.out.println("Your score is + "uscore" + :");
            if (dscore >= uscore)
                System.out.println("I won! get better!")
            if (uscore > dscore)
                System.out.println("Somehow, you beat me")
            

    Here is an example of what I've done before, and it needs to be fixed in several ways...
    my playing card value enum
    enum PlayingCardValue
        NO_CARD("","", 0, -1),  // placeholder so that ace starts at one
        ACE("A", "ace", 1, 11),  // has two values 1 or 11
        DEUCE("2", "deuce", 2, -1),  // everything else has only 1 numeric value
        THREE("3", "three", 3, -1),  // -1 is a marker that says "don't use this"
        FOUR("4", "four", 4, -1),
        FIVE("5", "five", 5, -1),
        SIX("6", "six", 6, -1),
        SEVEN("7", "seven", 7, -1),
        EIGHT("8", "eight", 8, -1),
        NINE("9", "nine", 9, -1),
        TEN("10", "ten", 10, -1),
        JACK("J", "jack", 10, -1),
        QUEEN("Q", "queen", 10, -1),
        KING("K", "king", 10, -1);
        private String shortName;
        private String name;
        private int value1;  // main valuve
        private int value2;  // -1 if not valid, a positive number if valid (if the ace)
        // enums have private constructors
        private PlayingCardValue(String shortName, String name, int value1, int value2)
            this.shortName = shortName;
            this.name = name;
            this.value1 = value1;
            this.value2 = value2;
        public String getRep()
            return this.shortName;
        public int getValue1()
            return this.value1;
        public int getValue2()
            return this.value2;
        @Override
        public String toString()
            return this.name;
    }my Playing card suit enum
    enum PlayingCardSuit
        SPADES ("spades"),
        HEARTS ("hearts"),
        DIAMONDS("diamonds"),
        CLUBS("clubs");
        private String name;
        private PlayingCardSuit(String name)
            this.name = name;
        @Override
        public String toString()
            return name;
    }My playingcard class
    * http://forum.java.sun.com/thread.jspa?threadID=5184760&tstart=0
    * @author Pete
    class PlayingCard
        private PlayingCardValue value;
        private PlayingCardSuit suit;
        public PlayingCard(PlayingCardValue value, PlayingCardSuit suit)
            this.value = value;
            this.suit = suit;
        public PlayingCardValue getValue()
            return this.value;
        public PlayingCardSuit getSuit()
            return this.suit;
        @Override
        public String toString()
            return this.value + " of " + this.suit;
    }You get the idea?

  • Simple array program help

    Hello could I please have some hints as to how to get this program working e.g. would it better to use a while loop for this? and how would I make the program stop when it has read 100 names?
    cheers anyone
    import java.util.*;
    import java.io.*;
    * The problem with files is generally you don`t know how many values
    * are in there. Develop a program to read names from a file - it carries
    * on and reads names until either 100 is reached or there is no more
    * data in the file. Display all the names read in together with the
    * count of how many names have been read.
    class Names100
         public void process (String[] argStrings)throws Exception
              int namesRead = 0;
              Scanner sc = new Scanner(new File("names.txt"));
              String[] namesArray = new String[100];
              for(int i = 0; i <= 100; i++)
                   namesArray[i] = sc.next();
                   System.out.println(namesArray);
                   namesRead++;
              System.out.println();
              System.out.println("Names read: " + namesRead);
              sc.close();

    > Thanks, the way that I have been taught at UNI means
    that I have a separate file called names100App (this
    is used to run the program).
    Ok, I understand.
    > The scanner is to get
    the content of the file although I could have used
    other things I guess.
    Yes, but the Scanner class is mighty handy.
    > Also I will check out what you said.
    >
    cheers
    John
    Good, and while you're at it, take a look at the ArrayList class (resizable-array implementation):
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
    Good luck.

  • Java concepts! Need help please!

    hi,
    im new to java, just started learning, im stuck on this last question in my assignment:
    Could anyone please help with answer:
    "Describe the followion OO programming concepts, explaining how they can be used to improve the writing and maintenance of software programs:
    Classes
    Objects
    Inheritence
    Overloading
    Overriding
    Interfaces"
    its worth 25 marks of the assignment.
    all help is appreciated
    Thanks

    Well, I suggest doing a search via google (the Internet has quite a bit of computer-related information available on it), or consulting more books. Go to your local public library or university library if you have one. You'll not learn much by copying down answers posted here.
    Lee

  • I was always instructed by Apple to install all updates.  I followed their advice and my Java disappeared and I can no longer play pogo scrabble.  pogo's "advice" to install Java is useless.  HELP PLEASE!

    I was always instructed by Apple to install all new updates offered.  When I installed the last one on my 10.5.7 macbook, my java disappeared.  Java's advice is useless.  I can no longer play pogo scrabble without java.  Please help.  Thank you very much.

    MadMAC0 posted at https://discussions.apple.com/message/20107182?ac_cid=tw123456#20107182 that:
    Apple has posted (10/22/12) the approved solution for restoring the Java 6 plug-in:
    Java for OS X 2012-006: How to re-enable the Apple-provided Java SE 6 applet plug-in and Web Start functionality.

  • Supermarket Array program help!

    class Supermarket {
        double[] profit;
        String[] city;
        String[] aboveAverage;
        double average,deviation;
        double list[], lenght;
        Supermarket(String[] thisCity, double[] thisProfit)
       city = thisCity;
       profit = thisProfit;
        @Override
    public String toString(){
            return "City" + '\t' + "Profit" + '\n' + city + '\t' + profit + 'n';
        public double getSum()
            double sum = 0;
            for(int i = 0; i < profit.length; i++)
                sum = sum + profit;
    return sum;
    public double average()
    return getSum()/profit.length;
    public String aboveAverage()
    String s = "";
    double avg = average();
    for(int i = 0; i < profit.length; i++)
    if(profit[i] > avg)
    s = city[i] + "" + profit[i] + '\n';
    return s;
    public double getDeviation()
    double sumdifference = 0;
    double mean = average();
    for(int i = 0; i < profit.length; i++)
    sumdifference = sumdifference + Math.pow((profit[i]- 1), mean);
    return Math.sqrt(sumdifference/profit.length);
    public double findhighValue()
    double highestValue = profit[0];
    for(int i = 1; i < profit.length; i++)
    if(profit[i] > highestValue )
    highestValue = profit[i];
    return highestValue;
    public double findlowestValue()
    double lowestValue = profit[0];
    for(int i = 1; i > profit.length; i++)
    if(profit[i] > lowestValue)
    lowestValue = profit[i];
    return lowestValue;
    public String barGraph()
    String s = "";
    for(int i = 0; i < profit.length; i++)
    s = s + city[i] + "";
    int x = (int)Math.floor(profit[i]);
    for(int j = 1; j <= i; j++)
    s = s + "*";
    s = s + '\n';
    return s;
    public int findPosition(int startfrom)
    int position = startfrom;
    for(int i = startfrom + 1; 1 < profit.length; i++)
    if(profit[i] < profit[position])
    position = i;
    return position;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.util.Locale;
    class TestSupermarket
    public static void main(String arg[])
    NumberFormat nf = NumberFormat.getInstance();
    DecimalFormat df = (DecimalFormat)nf;
    df.applyPattern("0.00");
    Locale local = Locale.US;
    NumberFormat cf = NumberFormat.getCurrencyInstance(local);
    double profit[] = {10200000, 14600000, 17000000, 6700000, 3600000, 9100000};
    String city[] = {"Miami", "Sunrise", "Hollywood", "Tallahassee", "Jacksonville", "Orlando"};
    System.out.println("Millions in revenue " + profit + city);
    Supermarket n = new Supermarket(city, profit);
    System.out.println("Average of profits " + cf.format(n.getSum()));
    System.out.println("\nThe average " + cf.format(n.average()));
    System.out.println("\nthe highest value " + cf.format(n.findhighValue()));
    System.out.println("\nthe lowest value " + cf.format(n.findlowestValue()));
    System.out.println("\nbargraph\t " + n.barGraph());
    System.out.println("\ndeviation " + n.getDeviation());
    System.out.println("\nposition " + n.aboveAverage());
    I'm still having some issues. 
    1st - Deviation calculation seems wrong, as it produces infinite.
    2nd -?     A horizontal bar graph showing the performance for each city, to the nearest million dollars.  Not sure how to produce that.
    3rd - ?     List in descending order of profit, the cities and their respective profit.
    I'm still working on this situation, but help is appreciated if you can set me to the right path.  Producing the array bar is the problem I'm mainly having.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I offered to help him stated at my last post in his topic. Different people, not sure how to prove we're different people other than IP check. He didn't need to produce "origin"city. Just the two arrays of Profit and city. I went ahead and develop a test class to test out the input.

  • PC Companion - Keeps crashing when trying to open the program Help Please

    Hi I hope someone caqn help,
    When i try to open PC Companion, i keep getting the message "Sony PC Companion has encountered a problem and needs to close" I've tried uninstalling the software and then re installing it but nothing works please i really need some help here.

    Do you have the latest version of Java installed?
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • I dont install the wallet sample to java card with gpshell . help please .?

    Hi
    I use Gemalto pc twin Reader.
    I try jdks(1.3.5 , 1.5 , 1.6 versions) for compile
    I use java card kit (2.1.1 , 2..1.2 , 2.2.1 ,2.2.2 versions) for create cap files
    For loadin used gpshell (1.4.2 , 1.4.1 , 1.3.1 versions)
    script
    enable_trace
    establish_context
    card_connect
    select -AID a0000000030000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    install_for_load -pkgAID a00000006203010C06 -nvCodeLimit 500 -sdAID A000000003000000
    load -file wallet.cap
    install_for_install -priv 02 -AID a00000006203010C0601 -pkgAID a00000006203010C06 -instAID a00000006203010C0601 -nvDataLimit 500
    get_status -element 20                                   
    card_disconnect
    release_context
    I didnt load wallet applet to card. Some time I take install_for_load error , some time install_for_install_and_make_selectable()
    Please help me.
    With jdk 1.3_5 , java card dev kit 2.1.2 and gpshell , I load applet to card but dont install and I take install_for_install_and_make_selectable returns 0x80206A80 (6A80 : Wrong data / incorrect values in command data) error.
    I dont understand why dont loaded the applet to card. Actually I load and install HelloWorld.cap file as this way.
    Additionally , In the wallet applet , the register method used as resigter(bArray , ..... .

    Anybody help me please. It very important. :(

  • Unlimited number of array elements, help please!

    Hi everyone,
    I have written this code for comparing two arrays but i don't know how to accept all types array lengths. Now i am limited to 5 elements and i want it to accept the the users desired number of elements. How should i do?
    import java.util.*;
    class console
    public static void main (String[] args)
    ConsoleInput ci = new ConsoleInput();
              System.out.print("Hur m�nga Vektorer ska lagras? ");
              int antal = ci.readInt();
              if (antal<2)
             System.out.println("Du beh�ver 2 st vektorer");
             System.out.println("Hur m�nga element per vektor?");
             int antalelement = ci.readInt();
              System.out.println();
                   for (int j=0 ; j<antal-1; j++)
                   System.out.print("Ange vektor1: ");
                   int vektor = ci.readInt();
                   int vektor3 = ci.readInt();
                   int vektor2 = ci.readInt();
                   int vektor4 = ci.readInt();
                   int vektor5 = ci.readInt();
                   int[] vektor1 = new int[] {vektor,vektor3, vektor2, vektor4, vektor5};
                  int langd = vektor1.length;
                  System.out.print("Ange vektor2: ");
                   int element1 = ci.readInt();
                   int element2 = ci.readInt();
                   int element3 = ci.readInt();
                   int element4 = ci.readInt();
                   int element5 = ci.readInt();
                   int[] vektor21 = new int[] {element1,element2,element3, element4, element5};
                   Arrays.sort (vektor21);
                    int  kopiera = vektor1.length + vektor21.length;
                             int[] nyvektor = new int [kopiera];
                              for(int i = 0; i < vektor1.length; i++)
                                   nyvektor[i] = vektor1;
                             for(int i = 0; i < vektor21.length; i++)
                                  nyvektor[vektor1.length + i] = vektor21[i];
              System.out.print("Unionen ar: ");
                                  verktyg.sort(nyvektor);
                                  int counter = 0;
                                  for(int k = 1; k < nyvektor.length; k++)
                                  if(nyvektor[k] == nyvektor[k-1])
                                  counter++;
                                  int[] union = new int[nyvektor.length - counter];
                                  union[0] = nyvektor[0];
                                  int b = 1;
                                  for(int k = 1; k < nyvektor.length; k++)
                                  if(nyvektor[k] != nyvektor[k-1])
                                                           union[b] = nyvektor[k];
                                                           b++;
                                                           for (int h = 0; h<union.length; h++)
                                                           System.out.print(" " +union[h]);
    System.out.println();
    System.out.print("Intersection ar: ");
    Arrays.sort(nyvektor);
                   int counter1= 0;
              for(int i = 1; i < nyvektor.length; i++)
              if(nyvektor[i] == nyvektor[i-1])
              counter1++;
                   int[] intersection = new int[counter1];
              //c[0] = C[0];
              int a = 0;
              for(int i = 1; i < nyvektor.length; i++)
              if(nyvektor[i] == nyvektor[i-1])
                                       intersection[a] = nyvektor[i];
                                       a++;
                        for(int i=0; i<intersection.length; i++)
                                       System.out.print(" " +intersection[i]);
    System.out.println();
    System.out.println("Differensen ar: ");
    Arrays.sort(nyvektor);
         int counter2 = 0;
                        for(int i = 1; i < nyvektor.length; i++)
                        if(nyvektor[i] == nyvektor[i-1])
                        counter2++;
                             int[] difference = new int[vektor1.length-counter];
                                                 boolean falsk = false;
                                                 int k=0;
                                                 for(int i = 0; i < vektor1.length; i++)
                                                      for(int d=0; d<vektor21.length; d++)
                                                                if(vektor1[i]!=vektor21[d])
                                                                     falsk = true;
                                                                else
                                                                     falsk = false;
                                                                     break;
                                                                if(falsk)
                                                                     difference[k] = vektor1[i];
                                                                     k++;
                                            for(int i=0; i<difference.length; i++)
                                  System.out.print(difference[i] + " ");

    How about this?import java.util.*;
    import java.io.*;
    class DynamicVectors
      public static void main (String[] args)
        BufferedReader console
          = new BufferedReader (new InputStreamReader (System.in));
        String consoleLine = "";
        StringTokenizer tokenizer;
        System.out.print ("Hur m�nga Vektorer ska lagras? ");
        try
          consoleLine = console.readLine();
        catch (IOException ioe)
          System.out.println (ioe);
        tokenizer = new StringTokenizer (consoleLine);
        int antal = Integer.parseInt (tokenizer.nextToken());
        if (antal<2)
          System.out.println("Du beh�ver 2 st vektorer");
        for (int j=0 ; j<antal-1; j++)
          int vektorSize;
          System.out.print("Ange vektor1: ");
          try
            consoleLine = console.readLine();
          catch (IOException ioe)
            System.out.println (ioe);
          // Here's where the fun starts...
          tokenizer = new StringTokenizer (consoleLine);
          vektorSize = tokenizer.countTokens();
          int[] vektor1 = new int [vektorSize];
          for (int i = 0; i < vektor1.length; ++i)
            vektor1 = Integer.parseInt (tokenizer.nextToken());
    // ...and that's all there is to it.
    int langd = vektor1.length;
    System.out.print("Ange vektor2: ");
    try
    consoleLine = console.readLine();
    catch (IOException ioe)
    System.out.println (ioe);
    // Here's where the fun starts...
    tokenizer = new StringTokenizer (consoleLine);
    vektorSize = tokenizer.countTokens();
    int[] vektor21 = new int [vektorSize];
    for (int i = 0; i < vektor21.length; ++i)
    vektor21 [i] = Integer.parseInt (tokenizer.nextToken());
    Arrays.sort (vektor21);

  • Java Matching and Patterns - help please.

    Ok, so I'm trying to take a CSV file and store it as an XML file using Java. Here's a sample line of the data file I'm working with:
    1001,"Fitzsimmons, Des Marteau, Beale and Nunn",109,"COD","Standard",,109,8/14/1998 8:50:02
    I'm trying to use regular expressions to match each field separately. I can't use split on "," because of the commas in the quotes (which is one whole field). So far, the first field matches to "[0-9]+," What would be the regex for the second field? "\".+\"," doesn't work, and I'm running out of ideas.

    I know this doesn't help the immediate problem, but I just have to say that this is the reason why comma is not a good separator. Why doesn't the world wake up and use tabs? I would assert that the chance of a value containing an embedded tab character is slim to none, whereas the chance that it contains any "printable" character is much greater - leading to this very headache.
    So actually this might help afterall, if you can get the separator changed.

  • Random Shut Down of the iTunes program - HELP PLEASE!

    My iTunes refuses to work! As of yesterday morning, every single time I try to open up the iTunes program, it does the following:
    1] Opens up to the Music Store
    2] The bar loads and says "Accessing Music Store"
    3] Before the Music Store can load even half way, iTunes closes. There is no message of error or any warning. It simply closes and nothing happens.
    I tried repairing iTunes, twice, and restarting my computer, and nothing helped. I then deleted iTunes, and then reinstalled the latest version, and THIS didn't help either. The only difference is that every time I click on the iTunes icon on my desktop, a license agreement comes up, and after I click "Agree," the same problem occurs over and over again.
    I was only able to play music once, yesterday afternoon, and I'm not quite sure why. My iTunes played two songs, and when a third came on, it shut off again and hasn't worked since. I recently had wireless Internet installed, and I'm wondering if this could be a contributing factor to my problem? I had my wireless installed about a week ago, but up until yesterday, everything was fine with my iTunes program. Also, I had a very fast, non-dial-up connection before [connected to a high speed internet box] and I did not have any iTunes related problems.
    I apologize for the length of this post/question! Thank you SO MUCH in advance for simply taking the time to read this! I am at such a loss when it comes to this issue, and any help or suggestions would be so amazingly appreciated. Thanks again.

    What kind of wireless router are you using?
    Also go into Win XP firewall (Start > Control Panel> and turn it off, just for a test. See if you can get into iTunes and play something.
    Remember to turn Win XP firewall back on.

  • Java.lang.NoClassDefFoundError: Simulation Help please!

    java.lang.NoClassDefFoundError: Simulation
         at SimulationController.setEnv(SimulationController.java)
         at EnvironmentController.setEnv(EnvironmentController.java)
         at EnvironmentController.openFile(EnvironmentController.java)
         at MBSGUIFrame$1.actionPerformed(MBSGUIFrame.java)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
         at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
         at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
         at java.awt.Component.processMouseEvent(Component.java:5100)
         at java.awt.Component.processEvent(Component.java:4897)
         at java.awt.Container.processEvent(Container.java:1569)
         at java.awt.Component.dispatchEventImpl(Component.java:3615)
         at java.awt.Container.dispatchEventImpl(Container.java:1627)
         at java.awt.Component.dispatchEvent(Component.java:3477)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
         at java.awt.Container.dispatchEventImpl(Container.java:1613)
         at java.awt.Window.dispatchEventImpl(Window.java:1606)
         at java.awt.Component.dispatchEvent(Component.java:3477)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    Exit code: 0
    No Errors
    This occurs when I try to run a data file through a case study program that I need for my examinations. I'm using RealJ 3.51, with SDK 1.4.2_09 The case study launches fine, and when I open the .dat file, I can see the fish which should begin to move, but that is when I get that error.

    Trying to guess... Does that class have a package or something?

  • Basic Tic Tac Toe programming help please

    I'm trying to make a seperate java class(there is another main that calls this using SWING interface) that makes mark on the board.
    It's supposed to do the following
    Method makeMark returns:
    a null if the cell indicated by row and column has already been marked
    an X if it is X's turn (X gets to go first)
    a Y if it is Y's turn
    Thus makeMark will have to keep of marks made previously and return the appropriate string
    for the requested cell.
    and here is what I got so far, but only getting empty clicks as a respond. Any help will be appreciated. thanks.
    import javax.swing.JButton;
    public class TicTacToeGame {
         public String makeMark(int row, int column){
    String player = "X";
    String [][] Enum = new String [3][3];
              for (row=0; row<=2; row++){
                   for (column=0; column<=2; column++)
                        if (Enum[row][column] == "")
    if (player == "X"){
    Enum[row][column] = "X";
    player = "Y";
    return "X";
    if (player == "Y"){
    Enum[row][column] = "O";
    player = "X";
    return "Y";
    else
    return null;
              return player;
    }

    ok is there a simpler codes that will just flip-flop between X and O? I had it working before but somehow it's not working anymore. Before I had
    public String makeMark(int row, int column){
    player = "X";
    if (player = "X")
    player = "O";
    else if (player = "O")
    player = "X";
    or soemthing like this but it used to work, but I had to revise the code to do more things and it stopped even flip-flopping between X and O.
    Here's main code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * This class is the GUI for TicTacToe. It only handles user clicks on
    * buttons, which represent X's and O's
    * @author Hal Mendoza
    * CSE 21 - Jan 18, 2011, 8:18:22 PM
    * TicTacToe.java
    public class TicTacToe extends JPanel implements ActionListener {
    public final static int NUM_ROWS_COLUMNS = 3;
    private JButton arrayofButtons[][] = new JButton[NUM_ROWS_COLUMNS][NUM_ROWS_COLUMNS];
    TicTacToeGame board = new TicTacToeGame();
    public TicTacToe() {
         BoxLayout ourLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
         setLayout(ourLayout);
         add(buildMainPanel());
    * Builds the panel with buttons
    * @return the panel with buttons
    private JPanel buildMainPanel() {
         JPanel panel = new JPanel();
         GridLayout gridLayout = new GridLayout(0, NUM_ROWS_COLUMNS);
         panel.setLayout(gridLayout);
         for (int row = 0; row < arrayofButtons.length; ++row)
              for (int column = 0; column < arrayofButtons[0].length; ++column) {
                   arrayofButtons[row][column] = new JButton();
                   arrayofButtons[row][column].setPreferredSize(new Dimension(50, 50));
                   arrayofButtons[row][column].addActionListener(this);
                   // Use actionCommand to store x,y location of button
                   arrayofButtons[row][column].setActionCommand(Integer.toString(row) + " " +
                             Integer.toString(column));
                   panel.add(arrayofButtons[row][column]);
         return panel;
    * Called when user clicks buttons with ActionListeners.
    public void actionPerformed(ActionEvent e) {
         JButton button = (JButton) e.getSource();
         String xORo;
         String rowColumn[] = button.getActionCommand().split(" ");
         int row = Integer.parseInt(rowColumn[0]);
         int column = Integer.parseInt(rowColumn[1]);
         xORo = board.makeMark(row, column);
         if (xORo != null)
              button.setText(xORo);
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event dispatch thread.
    private static void createAndShowGUI() {
         // Create and set up the window.
         JFrame frame = new JFrame("Tic Tac Toe");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         // Add contents to the window.
         frame.add(new TicTacToe());
         // Display the window.
         frame.pack();
         frame.setVisible(true);
    public static void main(String[] args) {
         // Schedule a job for the event-dispatching thread:
         // creating and showing this application's GUI.
         javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                   createAndShowGUI();
    }

  • Java WD: Dynamic Programming Help

    Hi,
    I've recently wrote a dynamic Java WD application to output a screen with a tabstrip that contains x tabs and each tab contains a table. Each table is mapped to a node in the context, and the nodes are static (precreated). Each table maps to it's own node and will not repeat.
    The steps are as follows:
    In the wdDoModifyView method I do the following
    1) Get the Tabstrip object using the view
    2) Create a IWDTab object (In a loop)
    2) Create a IWDTable
    3) Create many IWDTableColumns
    4) Create a IWDTextView for each column
    5) Bind to an attribute of the node
    Having done that, it appears to work fine. I do see my tabs and table created dynamically.
    Only problem any events is to occur on a table (e.g. select a cell (click on anywhere in the table), page up and page down using the footer controls, I get nasty Java dumps. (See below)
    Am I missing something here?
    Thanks in advance for any suggestions.
    Error stacktrace:
    com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Cannot find method onNAVIGATEPAGENEXT in adapter com.sap.tc.webdynpro.clientimpl.html.uielements.adaptmgr.URAdapterManager$DummyAdapter@1276390
         at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:839)
         at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.updateEventQueue(HtmlClient.java:722)
         at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.initEvents(AbstractClient.java:131)
         at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.prepareTasks(AbstractClient.java:99)
         at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:251)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:392)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)
    Caused by: java.lang.NoSuchMethodException: com.sap.tc.webdynpro.clientimpl.html.uielements.adaptmgr.URAdapterManager$DummyAdapter.onNAVIGATEPAGENEXT(java.util.Map)
         at java.lang.Class.getMethod(Class.java:986)
         at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:824)
         ... 23 more

    Michael,
    Actually, onNAVIGATEPAGENEXT is part of internal WD implementation, so you cannot do much about this error.
    I hardly beleive this is a bug because scrolling table is very common functionality, so it would be discovered much earlier.
    I guess that reason is IDE/WebAS version mismatch. Make sure that you are using IDE of same version as WebAS itself. Lower version of IDE is ok too, but not higher one. Probably the reason is here.
    VS

Maybe you are looking for

  • Problem with hello2 in the J2ee tutorial

    Hi all: I faced this problem when iam running the hello2 application I have followed the tutorial instructions and when i write the url in my browser http://localhost:8080/hello2/greeting but this error occur: HTTP Status 500 - type Exception report

  • Creation of Global Company code

    hi friends i have requirement like global company code i need to assign to my company code in oby6 where we will create this global company code. points will be awarded Thanks

  • Help Please!!! I get the following error message when attempting to download files.

    I get this message each time I try to download a file. my system tells me that Adobe Reader is up to date. What should I do? Please wait... If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be

  • In sap project who get lot of oppurtunities,sap abapers or sap bw people?

    hi all in general sap project in sap project who get lot of oppurtunities,sap abapers or sap bw people? thanks,

  • Developer account payment methods

    Hi... i live now in Germany... i want to sign up for  Developer iOS program... i hear that in germany have a prepaid credit card ( From Reise Bank).... can i use that to pay iOS Developer program ? Maybe you guys come from Germany can help me to answ