Click here to Skip to main content
16,011,702 members
Home / Discussions / Java
   

Java

 
Questionshortest remaining time first Pin
Blackberry8910-Apr-10 2:31
Blackberry8910-Apr-10 2:31 
AnswerRe: shortest remaining time first Pin
Richard MacCutchan11-Apr-10 14:34
mveRichard MacCutchan11-Apr-10 14:34 
GeneralRe: shortest remaining time first Pin
Blackberry8912-Apr-10 11:10
Blackberry8912-Apr-10 11:10 
GeneralRe: shortest remaining time first Pin
TorstenH.12-Apr-10 20:10
TorstenH.12-Apr-10 20:10 
AnswerRe: shortest remaining time first Pin
TorstenH.11-Apr-10 20:59
TorstenH.11-Apr-10 20:59 
Questionencrypting and decrypting an image Pin
glinseynew@gmail.com9-Apr-10 13:55
glinseynew@gmail.com9-Apr-10 13:55 
AnswerRe: encrypting and decrypting an image Pin
Richard MacCutchan11-Apr-10 14:32
mveRichard MacCutchan11-Apr-10 14:32 
QuestionSearch Array Pin
Blackberry899-Apr-10 8:58
Blackberry899-Apr-10 8:58 
Hello,
I have got two arrays one called NB(number of memory blocks) and the other called NJ(number of Jobs). I want the NB arrays to search through the jobs and find a job that is <= to the block. So for example if i had:

Blocks
800
300
750
200

Jobs
200
720
900
500

The 200 jobs should look the the blocks list and fit memory that best fits it, in this case that would be block 200. And job 720 should look through the list and instead of going to block 800 it should go to memory 750 as it best fits it.

Here is my code below so far:

import java.util.*;

public class BestFit
{
    public static final int NJ = 5;
    public static final int NB = 5;
    public static void main(String[] args) {
        
        int [][] Jobs = new int [NJ][2];
        int [][] block = new int [NB][2];
        Random random = new Random();
       
        
            for(int i=0; i<NJ; i++){
            Jobs[i][0] = -1; // job has not been allocated
            Jobs[i][1] = 100 + random.nextInt(900); //generate random number
        }
        
        for(int i=0; i<NB; i++){
            block[i][0] = -1; // memory block has not been allocated
            block[i][1] = 100 + random.nextInt(900);
            
        }
        
       
        for(int i=0; i<NJ;i++){
            for(int j=0; j<NB; j++){
                if(Jobs[i][1] <= block [j][1] && block[j][0] == -1 && Jobs[i][0] == -1){
                    block[j][0] = i;
                    Jobs[i][0] = j;
                    System.out.println("Job" +  Jobs[i][1] + " in memory" + block[j][1]);
                }
            }
        }
    
        
                   
        for(int i=0; i<NJ; i++){
            System.out.println("Job [" + i +"][0] = " + Jobs[i][0]); 
            System.out.println("Job [" + i +"][1] = " + Jobs[i][1]);
        }
        for(int i=0; i<NB; i++){
            System.out.println("block [" + i +"][0] = " + block[i][0]); 
            System.out.println("block [" + i +"][1] = " + block[i][1]);
        }
        
    }
        
         
}


thanks for all help
AnswerRe: Search Array Pin
Nagy Vilmos9-Apr-10 10:13
professionalNagy Vilmos9-Apr-10 10:13 
GeneralRe: Search Array Pin
Blackberry8910-Apr-10 0:10
Blackberry8910-Apr-10 0:10 
QuestionResizing Button?? Pin
AmbiguousName7-Apr-10 7:51
AmbiguousName7-Apr-10 7:51 
AnswerRe: Resizing Button?? Pin
TorstenH.8-Apr-10 1:59
TorstenH.8-Apr-10 1:59 
Questionhow to find jre is installed or not? Pin
002comp6-Apr-10 23:09
002comp6-Apr-10 23:09 
AnswerRe: how to find jre is installed or not? Pin
002comp6-Apr-10 23:27
002comp6-Apr-10 23:27 
QuestionResizing an image of Diamond shape and placing a label inside the image using Swing Pin
PJanaki6-Apr-10 4:14
PJanaki6-Apr-10 4:14 
AnswerRe: Resizing an image of Diamond shape and placing a label inside the image using Swing Pin
TorstenH.7-Apr-10 1:02
TorstenH.7-Apr-10 1:02 
GeneralRe: Resizing an image of Diamond shape and placing a label inside the image using Swing Pin
PJanaki14-Apr-10 2:40
PJanaki14-Apr-10 2:40 
Questionxampp in linux ubuntu Pin
hansoctantan5-Apr-10 16:51
professionalhansoctantan5-Apr-10 16:51 
AnswerRe: xampp in linux ubuntu Pin
David Skelly5-Apr-10 22:15
David Skelly5-Apr-10 22:15 
QuestionXMPP (Building an Instant Messaging Application Using Jabber/XMPP) Pin
Ireland.ir2-Apr-10 8:45
Ireland.ir2-Apr-10 8:45 
QuestionGenerate color scales in java please help!! Pin
codonneem1-Apr-10 5:05
codonneem1-Apr-10 5:05 
AnswerRe: Generate color scales in java please help!! Pin
David Skelly5-Apr-10 22:29
David Skelly5-Apr-10 22:29 
QuestionUnable to start the Tomcat v6.0 Server Pin
Ram Bonala26-Mar-10 3:59
Ram Bonala26-Mar-10 3:59 
AnswerRe: Unable to start the Tomcat v6.0 Server Pin
Richard MacCutchan26-Mar-10 5:03
mveRichard MacCutchan26-Mar-10 5:03 
AnswerRe: Unable to start the Tomcat v6.0 Server Pin
xxyyjoke26-Mar-10 15:03
xxyyjoke26-Mar-10 15:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.