r/javahelp • • Mar 05 '23

Solved Implementing a method within a toString method

0 Upvotes

I'm writing a class in which I have a class representing a circle. With the radius, two public methods were created to calculate the area and perimeter respectively. How might I call these methods in the toString method of the class? I have attached some of the class for visual representation.

Note: There is no good reason for you to down vote my posts.


r/javahelp • • Mar 05 '23

intellij idea

0 Upvotes

i tried to make a code that allows the user to input a double number but it only worked if i used a comma instead of a decimal. like if i were to input a number for a price of an item “2.00” would create an error but “2,00” works. my intellij is in english and also i checked the settings on my laptop and it uses a period for money and a comma to group numbers so 40,000.00. what do i do to fix this?

EDIT: this is my code public class Store { String fruit; double price; int quantity;

public Store(String fruit, double price, int quantity, String email) {
    this.fruit = fruit;
    this.price = price;
    this.quantity = quantity;
}

public String getFruit() {
    return fruit;
}

public double getPrice() {
    return price;
}

public int getQuantity() {
    return quantity;
}

}

import java.util.Scanner; public class Customer { public static void main(String[] args) { Customer customers = new Customer(); customers.getProducts(); } public void getProducts() { Scanner scan = new Scanner(System.in); System.out.println("Enter fruit: "); String fruit = scan.nextLine(); System.out.println("Enter price: "); double price = scan.nextDouble(); System.out.println("Enter quantity: "); int quantity = scan.nextInt(); System.out.println("Thank you!"); } }

sorry idk how to get it into the format

https://imgur.com/a/ffi12Og here are screenshots of it. it only runs if i use a comma instead of a decimal


r/javahelp • • Mar 21 '23

Need help converting all number grades to letter grades!

0 Upvotes

Hi, I have to convert all number grades (ie: 87) to letter grades;

A’ – 80% or higher

‘B’ – 70%-79%

‘C’ – 60%-69%

‘D’ – 50%-59%

‘F’ – less than 50%

So it should have all the number grades stored but it should print as letter grades. Anyone know how?

I thought of using replace() but im not sure how to implement that. 'if' statements might work? but that seems like that'll be a lot of them and i wanna do this efficiently as im trying to get a little better with that. Any ideas?

MAIN CLASS:

import java.util.Scanner;

public class GradesResults
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        // First Student; 
        Grades student1 = new Grades("Marina", 345345654, 21, 65, 42, 77, 53, 57.6);
        System.out.println(student1);
        System.out.println();
        
        // New First Student Info (ONLY grades + average must be changed)
        double oldAverage1 = 57.6;
        System.out.print("Enter a new grade to replace 21: ");
        int assess1 = input.nextInt();
        int x = 21;
        x = assess1;
        System.out.print("Enter a new grade to replace 42: ");
        int assess2 = input.nextInt();
        input.nextLine();
        int y = 42;
        y = assess2;
        double newAverage1 = ((x + 65 + y + 77 + 53) / 5);
        // Separate with hearts (for fun)
        System.out.println();
        System.out.println("♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡");
        System.out.println();
        System.out.println("Student 1's new grades are " + x + ", 65, " + y + ", 77, and 53.");
        // Two 'if' statements to declare whether or not the average went up or down
        if (newAverage1 > oldAverage1) {
            double sub1 = newAverage1 - oldAverage1;
            // Round the average so you dont end up with a bunch of 0's
            sub1 *= 100;
            sub1 += .5;
            sub1 = (int)sub1;
            sub1 /= 100;
            System.out.println("Their average went up by " + sub1 +" and is now: " + newAverage1);
        }
         if (oldAverage1 > newAverage1) {
            double sub1 = oldAverage1 - newAverage1;
            // Rounding again
            sub1 *= 100;
            sub1 += .5;
            sub1 = (int)sub1;
            sub1 /= 100;
            System.out.println("Their average went down by " + sub1 + " and is now: " + newAverage1);
        }
        
        // Separate with spades (for fun)
        System.out.println();
        System.out.println("♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣");
        System.out.println();
        // Second Student
        Grades student2 = new Grades(354123657, 95, 60, 77, 81, 50);
        System.out.println(student2);
        // Separate with flowers (for fun)
        System.out.println();
        System.out.println("❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁❁");
        System.out.println();
        // Third Student
        Grades student3 = new Grades("Marina");
        System.out.println(student3);
        // Separate with hearts (for fun)
        System.out.println();
        System.out.println("♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡♡");
        System.out.println();
        // Fourth Student
        Grades student4 = new Grades();
        System.out.println(student4);
        
        System.out.println();
        
        // New Fourth Student Info (all info must be changed)
        // Ask user for a New Name
        System.out.print("Enter a new name: ");
        String stu4name = input.nextLine();
        // Ask user for a New Student Number
        System.out.print("Enter a new student number: ");
        int stu4num = input.nextInt();
        input.nextLine();
        // Ask user for a New Course Code
        System.out.print("Enter the first 3 letters of a new course code (all caps): ");
        String stu4code1 = input.nextLine();
        System.out.print("Now the number: ");
        int stu4code2 = input.nextInt();
        input.nextLine();
        System.out.print("Now the last letter: ");
        String stu4code3 = input.nextLine();
        String stu4code = (stu4code1 + (int)stu4code2 + stu4code3);
        
        System.out.println();
        // Ask user for New Grades
        double oldAverage2 = 96.2;
        System.out.print("Enter a new grade to replace 99: ");
        int assess3 = input.nextInt();
        int a = 99;
        a = assess3;
        System.out.print("Enter a new grade to replace 97: ");
        int assess4 = input.nextInt();
        int b = 97;
        b = assess4;
        System.out.print("Enter a new grade to replace 92: ");
        int assess5 = input.nextInt();
        int c = 92;
        c = assess5;
        System.out.print("Enter a new grade to replace 95: ");
        int assess6 = input.nextInt();
        int d = 95;
        d = assess6;
        System.out.print("Enter a new grade to replace 98: ");
        int assess7 = input.nextInt();
        int e = 98;
        e = assess7;
        double newAverage2 = ((a + b + c + d + e) / 5);
        // Printing all the new Info
        // Separate with spades again (for more fun)
        System.out.println();
        System.out.println("♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣");
        System.out.println();
        // Print New Name
        System.out.println("Student 4's new name is: " + stu4name + ".");
        // Print New Student Number
        System.out.println("Student 4's new student number is: " + stu4num + ".");
        // Print New Course Code
        System.out.println("Student 4's new course code is: " + stu4code + ".");
        // Print New Grades and Average
        System.out.println("Student 4's new grades are " + a + ", " + b + ", " + c + ", " + d + ", and " + e + ".");
        // Two 'if' statements to declare whether or not the average went up or down
        if (newAverage2 > oldAverage2) {
            double sub2 = newAverage2 - oldAverage2;
            // Rounding again
            sub2 *= 100;
            sub2 += .5;
            sub2 = (int)sub2;
            sub2 /= 100;
            System.out.println("Their average went up by " + sub2 +" and is now: " + newAverage2);
        }
         if (oldAverage2 > newAverage2) {
            double sub2 = oldAverage2 - newAverage2;
            // Rounding again
            sub2 *= 100;
            sub2 += .5;
            sub2 = (int)sub2;
            sub2 /= 100;
            System.out.println("Their average went down by " + sub2 + " and is now: " + newAverage2);
        }
    }
}

OTHER CLASS:

public class Grades 
{
        // This class consists of constructors to create default
        // prompts in the output. The user will be prompted to change
        // whatevers needed to be changed in the main class.
        // Instance variables that identify:
        // course code
        private String courseCode;
        // student number
        private int stuNum;
        // student name
        private String name;
        // student school number
        private int num;
        // each individual grade
        private int grade1;
        private int grade2;
        private int grade3;
        private int grade4;
        private int grade5;
        // grade average
        private double average;
        // Student 1; course code, student school number, and student name are NOT subject to change
        // the grades and average ARE subject to change via user input
        public Grades(String studentName, int studentNumber, int studentGrade1, int studentGrade2, int studentGrade3, int studentGrade4, int studentGrade5, double studentAverage) {
            courseCode = "ICS" + 4 + "U";
            stuNum = 1;
            name = studentName;
            num = studentNumber;
            grade1 = studentGrade1;
            grade2 = studentGrade2;
            grade3 = studentGrade3;
            grade4 = studentGrade4;
            grade5 = studentGrade5;
            average = studentAverage;
        }
        // Student 2; NOT subject to change, student #, grades, and average 
        // will be constructed in the main class
        public Grades(int studentNumber, int studentGrade1, int studentGrade2, int studentGrade3, int studentGrade4, int studentGrade5) {
            courseCode = "ICS" + 4 + "U";
            stuNum = 2;
            name = "Melody";
            num = studentNumber;
            grade1 = studentGrade1;
            grade2 = studentGrade2;
            grade3 = studentGrade3;
            grade4 = studentGrade4;
            grade5 = studentGrade5;
            average = ((studentGrade1 + studentGrade2 + studentGrade3 + studentGrade4 + studentGrade5) / 5);
        }
        // Student 3; NOT subject to change, student name will be constructed in the main class
        public Grades(String studentName) {
            courseCode = "ICS" + 4 + "U";
            stuNum = 3;
            name = studentName;
            num = 334631900;
            grade1 = 99;
            grade2 = 97;
            grade3 = 92;
            grade4 = 95;
            grade5 = 98;
            average = 96.2;
        }
        // Student 4; ALL is subject to change via user input in the main class
        public Grades() {
            courseCode = "ICS" + 4 + "U";
            stuNum = 4;
            name = "Melody";
            num = 334631900;
            grade1 = 99;
            grade2 = 97;
            grade3 = 92;
            grade4 = 95;
            grade5 = 98;
            average = 96.2;
        }
        // toString method to display all pre-entered information
        public String toString()
        {
            return "Student " + stuNum + "'s name is: " + name + ". Their student number is: " 
            + num + ", and they have a course average of: " + average + " in " + courseCode + 
            " based off 5 assessment marks: " + grade1 + ", " + grade2 + ", " + grade3 + ", "
            + grade4 + ", " + grade5 + ".";
        }
}

r/javahelp • • Mar 12 '23

help on java

0 Upvotes

hello every one i hope that u r all right just i want some advices about learning java and how to practice it

please if you have any web site or document could help me please send it

have a nice day all


r/javahelp • • Jul 19 '17

Alphanumeric password input

0 Upvotes

I'd like to have an idea on how to make this program please.

It asks for an input password that meets these conditions:

-at least 6 characters long

-contains 1 capital letter or more

-alphanumeric

It denies the input if it doesn't meet those conditions, no need to hide it in asterisks.

I'm kinda new to Java and any kind of help will be appreciated


r/javahelp • • Jul 16 '17

Can someone explain this to me?

0 Upvotes
public class hoho{
       public static void main(String[] args){
             String x = "java";
             String y = "tyler";
             String z = "tv";
             String rugby = "hamburger";
            String java = "donnie";

            hamburger(x, y, z);
            hamburger(z, x, y);
            hamburger("rugby", z, java);
            hamburger(y, rugby, "x");
            hamburger(y, y, "java");
       }

     public static void hamburger(String y, String z, String x) {
           System.out.println(z + " and " + x + " like " + y);
}
    }

tyler and tv like java java and tyler like tv tv and donnie like rugby hamburger and x like tyler tyler and java like tyler

So I got up to Java and tyler like tv...but now I'm stuck with the 3rd part... I don't get how it's TV and donnie like rugby...? as well as the other two below


r/javahelp • • Nov 20 '23

Codeless What are good java projects in Github that are easy to compile for research purposes?

0 Upvotes

Hello

I'm looking for projects in Github that have minimum requirements to compile. I will be compiling them using either NetBeans or java command line.

Some applications require several tools in order to compile which led to my pc being full of tools. Sorry if I sound silly, I'm just looking for something that is easy to build and require minimal tools.

Many thanks in advance.


r/javahelp • • Jan 26 '24

Can you please explain me why java needs package declaration?

0 Upvotes

I mean what's the point? Whenever I import something from a java extension file I'll declare a path in my code? No?

Like in JavaScript it's just: import someThing from './utilis/some_thing.js';

So I don't need to declare in that some_thing.js file that it resides in utilis directory.

So why java needs it? It kinda bugs me and I want to understand.

Thanks beforehand!


r/javahelp • • Feb 03 '24

DSA!!

0 Upvotes

thinking to start DSA (in java), best resources to learn DSA and tips/advice/suggestions.


r/javahelp • • May 14 '13

How to solve? (2 easy problems)

0 Upvotes
  1. Print a flag based on input.

e.g. when input of 1, print:

+-----

|....../

|......\

+-----

input of 2, print:

+-------

|......../

|......./

|.......\

|........\

+-------

3 = bigger, 4 = even bigger, etc

.

.

.

.

2)

Print an output describing whether the input is considered a stutter or not. A string is considered a stutter if letters repeat twice, e.g. 11223344, aabbccdd, ccaatt

abcabc, 123123 are not stutters.

.

.

.

.

I am looking for any help, a complete program, some pseudocode, or just some hints towards the right direction. Thank you. Also, sorry, I don't know how to format reddit properly.


r/javahelp • • Mar 21 '15

How can I practice?

0 Upvotes

I'm new to java (Not a complete newbie though) and I want to practice for learning, but I don't know what to do to practice, can someone give me some pointers? Preferably by making something but I don't know what. :) (I don't know if this is the right place to ask this but it was the first thing I thought of)


r/javahelp • • Jun 06 '16

Anyone interested in building an convolutional neural network using low-level java libs to recognize street signals and execute action based on them

0 Upvotes

Hi,

my idea is to build a very simple mobile cam app that pre-processes the camera capture in that way

  • that it takes the red and green channel

  • from a small region of interest (where we expect the signal to appear)

  • to max pool the ROI (to reduce amounts of data)

  • the app has a button which should be manually pressed whenever the signal turns from red to green.

  • and to transmit the data to a simple web application

Should be realized in a streaming, the web app receive a constant stream of data to feed the network

The network should be a convolutional neural network. When trained it should be able to recognize the turn from a red to a yellow and green light (r = red light, g = green light, b = red and green light)

When confident the model should trigger the execution of sending back 'button press' command to the mobile app.

The network should get trained constantly, the model should be updated regularly.

Thanks. Is there anyone who feels confident to program that in a few weeks with me?


r/javahelp • • Mar 25 '15

call method help

0 Upvotes
import javax.swing.JFrame;

import javax.swing.SwingUtilities;

public class JFrame_test {

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        
        @Override
        public void run() {

    JFrame1 frame1 = new JFrame1("first JFrame");
    JFrame2 frame2 = new JFrame2("second JFrame");      

    frame1.setSize(200, 300); 
    frame1.setLocation(200,0);
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame1.setVisible(true);
    
    frame2.setVisible(true);
    frame2.setSize(200, 300);
    frame2.setLocation(0,0);
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame2.setVisible(true);

        }
    });
}
}


import javax.swing.JFrame;

public class JFrame1 extends JFrame{

public JFrame1(String a)
{
	System.out.println(a);
}

public void greeting()
{
	System.out.println("hi");
}

}


import javax.swing.JFrame;

public class JFrame2 extends JFrame{

public JFrame2(String a)
{
	System.out.println(a);
	frame1.greeting();
}

}

help. i want call greeting function in JFrame2 class.


r/javahelp • • Jun 01 '16

What's the easiest way to set a background color?

0 Upvotes

I'd like to set my background as red. What would be the easiest way?


r/javahelp • • Jun 08 '16

Need help with question

0 Upvotes
class A{
  static class B{}
  static class C{ B b;
    C(B b){this.b=b;}
    int foo(){return 42;}
  }
}
public class Exercise{

  public static void main(String [] arg){
    assert ([???].foo()==42);
  }
}

Gotta full in the ???


r/javahelp • • May 19 '20

doing switch case statement and cant convert boolean to int

0 Upvotes

doing pay assignment and need to set a pay level to a wage and doing

switch(wage)

{

case(lvl=1)

wage=17;

break;

}

and so on its telling me i need to change lvl to a boolean even tho im asking for a lvl 1-3


r/javahelp • • Jun 22 '20

How do I open a jpanel from within a jframe?

0 Upvotes

Ive tried MyFrame.add(Mypanel); but that doesn’t do anything


r/javahelp • • Jun 24 '20

Workaround How to write a polymorphic visitor?

0 Upvotes

I have code like the following. Is there an easy way to make this work and work type safely?

I know I could pass on a witness but that is ugly.

public interface TermVisitor<B, C> {

    <Domain, Range> C lambda(Variable<Domain> binder, Term<Range> body);


    <A> C apply(Term<Function<A, B>> f, Term<A> x);


    C global(Global<B> global);


    C constant(Constant<B> constant);


    C local(Variable<B> binder);

}

public interface Term<A> {

    <C> C visit(TermVisitor<A, C> visitor); 

}

public record LambdaTerm(Variable<Domain> binder, Term<Range> body) implements Term<Function<A, B>> {

}

r/javahelp • • Jun 02 '20

Dijkstra using PriorityQueue and Collections

0 Upvotes

I have problem implementing Dijkstra's algorithm in Java using PriorityQueue. The program is not checking all the nodes . PLEASE I NEED HELP FIXING THIS. here is the code :

https://hasteb.in/amuhemig.cs


r/javahelp • • Jun 21 '20

JAVA CORE PLUS SPRING

0 Upvotes

When programming web applications with the Spring Framework, are Java Core's algorithms important and applicable to Spring? For example, arrays, backtracking, binary trees, ... are applied to the Spring framework or not and is it necessary to learn good data structures and algorithms in Java Core? How are they applied to Spring? Thanks📷


r/javahelp • • Dec 31 '19

Java MOOC Exercise 59

0 Upvotes
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class WordsInReverseOrder {

public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);
    // create here an ArrayList
    ArrayList<String> words = new ArrayList<String>();
    System.out.println("Type a word:");
    String word = reader.nextLine();
    words.add(word);

    while (/*word != null &&*/!word.isEmpty()) {
        word = reader.nextLine();
        words.add(word);
    }
    if (word.isEmpty()) {
        System.out.println("You typed the following words: ");
        for (int i = words.size()-1; i >= 0; i--) {
            System.out.println(words.get(i));
        }
    }
}

}

Can anyone explain why I can't use the method reverse?


r/javahelp • • Jun 08 '19

Why is there a NullPointerException?

0 Upvotes

Hi all!

Please check my method below, for some reason I get NullPointerException for line 9.

countryArray is an array of strings, with countries, but then it is also filled with a bunch of null after the list of countries is over.

  1.     public static void golds(String[] countryArray) {

  2.         //int count = 0;

  3.         String currentCountry = new String();

  4.         for (int i = 0; i < countryArray.length; i++) {

  5.             currentCountry = countryArray[i];

  6.             int count = 0;

  7.             for (int j = 0; j < countryArray.length; j++) {

  8.                 if (countryArray[j] != null) {

  9.                     if (currentCountry.equals(countryArray[j])) { // FIX THE NULL POINTER ERROR!!!!!!!!!

  10.                         count++;

  11.                     }

  12.                 }

  13.                 else {

  14.                     j = countryArray.length;

  15.                 }

  16.             }

  17.         }

  18.         countryArray = removeDuplicates(countryArray);

  19.         System.out.println("Count of gold medalists by country:");

  20.         for (int g = 0; g < countryArray.length; g++) {

  21.             System.out.println(countryArray[g]);

  22.         }


r/javahelp • • Mar 31 '19

java.lang.OutOfMemoryError

0 Upvotes

I made a dice project for my AP Comp class where it would use the console to display dice constructed from an array of strings. Later I modified it so that it would display which numbers where rolled how many times. I was recently messing around with it and I changed the constants so it would generate ten random numbers per roll and complete one billion rolls. It ran the code up until it was supposed to parse the array and display how many times each number was rolled. Underneath is the code I have written:

import java.util.*; public class DiceNineSide { private static final int DICENUM = 10; private static final Scanner in = new Scanner(System.in); private static final int LIMIT = 1000000000; public static void main(String[] args) { int count = 0; int[] averageInt = new int[LIMIT]; String play = "yes"; String[][] setOfDice = constructDice(); checkDiceNum(); //play.equalsIgnoreCase("yes") while (count < LIMIT){ //printDice(constructDice()); String[][] diceSet = new String[DICENUM][DICENUM]; int[] storeInt = new int[DICENUM]; int sum = 0; rollDice(diceSet, setOfDice, storeInt); //printDice(diceSet); for(int i = 0; i < storeInt.length; i++){ sum += storeInt[i]; } averageInt[count] = sum; count++; //play = in.next(); //line(); } numberCount(averageInt); countNum(count); } private static String[][] constructDice(){ String topBot = " --------- "; String E = "| |"; String M1 = "| * |"; String M2 = "| * * |"; String L1 = "| * |"; String R1 = "| * |"; String M3 = "| * * * |"; String[] One = {topBot, E, M1, E, topBot}; String[] Two = {topBot, E, M2, E, topBot}; String[] Three = {topBot, L1, M1, R1, topBot}; String[] Four = {topBot, M2, E, M2, topBot}; String[] Five = {topBot, M2, M1, M2, topBot}; String[] Six = {topBot, M2, M2, M2, topBot}; return new String[][]{One, Two, Three, Four, Five, Six}; } private static void printDice(String[][] allDice){ for(int dice = 0; dice < allDice[0].length; dice++){ // for (int side = 0; side < allDice.length; side++) // System.out.print(allDice[side][dice] + "\t"); for (String[] anAllDice : allDice) System.out.print(anAllDice[dice] + "\t"); System.out.println(); } } private static void line(){ for(int i = 0; i < 14 * DICENUM; i++) System.out.print("-"); System.out.println(); } private static int[] rollDice(String[][] diceSet, String[][] setOfDice, int[] storeInt){ for(int i = 1; i <= DICENUM; i++){ int roll = (int) Math.round(Math.random() * (constructDice().length - 1)); diceSet[i - 1] = setOfDice[roll]; storeInt[i - 1] = roll + 1; } return storeInt; } private static void checkDiceNum(){ if(DICENUM <= 0){ System.exit(-2); } } private static void countNum(int count){ if(count == 1) System.out.println("You rolled once."); else System.out.println("You have rolled " + count + " times."); } private static void numberCount(int[] countDice){ int[] count = new int[LIMIT]; for(int i = 0; i < countDice.length; i++){ count[countDice[i] - 1]++; } for(int i = DICENUM - 1; i < (DICENUM * constructDice().length); i++){ if(count[i] != 1){ System.out.println("You rolled a " + (i + 1) + " - " + count[i] + " times."); }else{ System.out.println("You rolled a " + (i + 1) + " - 1 time."); } } } }


r/javahelp • • Mar 28 '19

I have no idea what to do i have tryed eavrything it dosent work pls HELP!!!!1

0 Upvotes

Hey guys I need some help my Minecraft keeps crashing I dont have many mods 20 and my game keeps chrashing at random sometimes need some help pls i have tryed everything.I am raly frustrated !!!!!!

There is insufficient memory for the Java Runtime Environment to continue.

and yes i have tryed alocating more RAM i have it 4 gb out of 8

# Native memory allocation (malloc) failed to allocate 1110736 bytes for Chunk::new

# Possible reasons:

# The system is out of physical RAM or swap space

# In 32 bit mode, the process size limit was hit

# Possible solutions:

# Reduce memory load on the system

# Increase physical memory or swap space

# Check if swap backing store is full

# Use 64 bit Java on a 64 bit OS

# Decrease Java heap size (-Xmx/-Xms)

# Decrease number of Java threads

# Decrease Java thread stack sizes (-Xss)

# Set larger code cache with -XX:ReservedCodeCacheSize=

# This output file may be truncated or incomplete.

#

# Out of Memory Error (allocation.cpp:390), pid=13820, tid=12788

#

# JRE version: Java(TM) SE Runtime Environment (8.0_51-b16) (build 1.8.0_51-b16)

# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.51-b03 mixed mode windows-amd64 compressed oops)

# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

#