Hey Sup Forums

Hey Sup Forums

I need a bit of help with some java shit, essentially what I need is a block of code that will take a number, let's say 50, and count how many 12's for example, that are in it and the remaining amount, I have the base code it's just that I suck ass at when it comes the the maths part of coding. Preferably in the form of a method with generic identifier names that I can change for different purposes.

I'm not gonna lie it's for my IT course, I had to miss a lot of java classes cause I got pretty fucked up from a pretty bad crash while mountain biking in the woods and now I gotta catch up with all the assignments.

If anyone could help that'd be great.

Other urls found in this thread:

stackoverflow.com
twitter.com/SFWRedditImages

Sup Forums isn't really the place for this. I recommend:
stackoverflow.com

> how do i divide

I know how to divide buddy, it's just that I suck at the writing the actual maths parts out in a way that actually works, it never wants to compile when I have tried writing maths procedures so I'm assuming I'm doing something wrong, so that's why I'm here

x=12
y[]
int count
for(){
if y[]=x
count++
}
println count
println (y.length-count)

(code it yourself)

Are u fernando's father?

What math bit, just divide it to an int(number) and subtract the original with the amount*number

Nah, I remember that whole thing though, shit was hilarious

Any of you really good coders?

>integer division
>mod
Learn to google faggot

who is spamming Sup Forums at the moment?

>can't math
Nigga you just went full retard

...

...

...

...

...

Yeah you are being vague. One user already posted code that basically looks at a set of numbers (1d vector y) and looks at them one at a time to count how many times 12 shows up in the list of numbers. I do think I see some errors in assignment versus equivalence but maybe it's because I don't code in java.

I first interpreted your problem as modular arithmetic (scalar y, not 1d vector). Modular division just is a formal way to define remainder. So 50/12 is 4 with remainder 2. There might be a built in modulus function or you will need to divide and then use rounding/integer part to separate the integer part from the decimal remainder or whole number remainder.

...

...

...

I'm on my phone so this will look like shit

int HowManyNumbersOnAnotherNumber(int divideFrom, int smallerNumber)
{
if (divideFom == 0)
{
return -1; // or throw a DivideByZeroException or whatever
}
int times = 0;
while (divideFrom % smallerNumber == 0)
{
divideFrom /= smallerNumber;
times++;
}
}

Try running that.

...

double urNum = sc.nextDouble();
double urOtherNum = sc.nextDouble();

int rest;
int numberOfTimes;

rest = urNum%urOtherNum;

numberOfTimes = (urNum - rest)/urOtherNum;

System.out.print("The rest is " + rest + " and the number " + urOtherNum);

Fuck, I forgot to return times after the while loop. You should be able to figure that out OP, I did the leg work. Also there's one spelling error.

...

You ok user?

By the way, Ive been having some trouble with my code, I can open an image with buffered reader, but I don't know how to then close the program (after the other programs have finished acting), can anyone help me close the file (and not a editor.close at the end or sleep, but to run a new method that closes the current one)


public static void open(String file){
String filename=file+".jpg";
//JFrame editorFrame=null;
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
JFrame editorFrame = new JFrame(filename);
editorFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

BufferedImage image = null;
try
{
image = ImageIO.read(new File(filename));

}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
ImageIcon imageIcon = new ImageIcon(image);
JLabel jLabel = new JLabel();
jLabel.setIcon(imageIcon);
// editorFrame.getContentPane().add(jLabel, BorderLayout.CENTER);
editorFrame.getContentPane().add(jLabel, BorderLayout.WEST);
editorFrame.pack();
editorFrame.setLocationRelativeTo(null);
editorFrame.setVisible(true);


}
});
}

google.com "JFrame close"

Nope, I want to display it and let it interact with other methods, so I can't close it in the loop and Everything I have tried to send the editorframe out of the loop fails, so it can't identify the exact thing it needs to close outside the loop

Private static closeFrame (JFrame frame){
frame.Close ();
}

Floor division and modulo you dickhead