|
There must be some strange characters still in your source files.
|
|
|
|
|
I just did a test with the same characters in another project, and I don't have that problem, it is really strange. Oh well, I'll figure it out in time.
|
|
|
|
|
There must be a character in there somewhere that is not getting displayed. Use a hex editor to find it.
|
|
|
|
|
The problem was from Eclipse. I had to remove those characters and then add them again. For some reason it wasn't recognizing then anymore and was adding some weird characters instead in the files.
|
|
|
|
|
So, the solution was to add:
-cp "The location of src folder" (you need the " ")
-encoding utf8
|
|
|
|
|
I am doing a project in java that requires to detect the number of fingers in the image
I want to know how to do that or sample code for this task .
|
|
|
|
|
Google for "Java image recognition".
|
|
|
|
|
i had starting learning java one month age but till now i dont think i had gain even 1% of knowledge please help
|
|
|
|
|
|
Hi,
I'm in a full stack training program and we are currently working on an inter-team project comprised of RESTful services in a microservice architecture. I've been put in charge of back-end unit testing for and am currently researching various test APIs. In addition to JUnit, I'm trying to determine whether I should use REST-assured, Mockito, or both. Reading through the documentation and reading/watching various tutorials has been a bit confusing though. My understanding so far is that REST Assured is for endpoint testing and Mockito is for unit testing. Can someone please give advice as to which would be better to use, or should I be using them both?
Basically, it would be for testing basic CRUD functionality in Spring MVC apps on the service and controller layers.
Any help or advice is greatly appreciated! Also, I can provide more information if you want, I realize it's kind of an open-ended question.
|
|
|
|
|
|
This is the Java forum. What language is that code in your picture?
|
|
|
|
|
It's written in "spam".
The words "tick to view" are a link to an essay writing site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I (foolishly) assumed it was a single link.
|
|
|
|
|
Hey guys!
I'm just trying to figure out this homework and could use some help. Not looking for answers really, just a better understanding. I'm very very new to coding, using jGRASP java. The teacher told us to create this game that generates an output similar to this.
Round 1:
• Player A rolls: 1,2, the highest number is 21
• Player B rolls: 2,1, the highest number is 21
• Result: draw
• Round 2:
• Player A rolls: 2,5, the highest number is 52
• Player B rolls: 6,8 the highest number is 86
• Result: Player B wins
• Round 3:
• Player A rolls: 1,9, the highest number is 91
• Player B rolls: 9,9 the highest number is 99
• Result: Player B wins
• Final Result: Player B wins!!!
Do I have to declare the numbers as Strings to concatenate them? and do I use if else statements? Specifically, I'm confused on how to arrange the two numbers if one is greater than the other so the greater number will be placed in front.
import java.util.Scanner;
import java.util.Random;
public class beatThat
{
public static void main(String[] args)
{
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
Random r4 = new Random();
int die1 = r1.nextInt(6) + 1;
int die2 = r2.nextInt(6) + 1;
int die3 = r3.nextInt(6) + 1;
int die4 = r4.nextInt(6) + 1;
System.out.println("ROUND 1");
System.out.println("Player A rolls: " + die1 + " and " + die2 +".");
System.out.println("Player B rolls: " + die3 + " and " + die4 +".");
if(die1 >= die2)
{
System.out.println("Player A's highest number is: " + die1 + die2);
}
else if (die2 >= die1)
{
System.out.println("Player A's highest number is: " + die2 + die1);
}
if(die3 >= die4)
{
System.out.println("Player B's highest number is: " + die3 + die4);
}
else if(die4 >= die3)
{
System.out.println("Player B's highest number is: " + die4 + die3);
}
}
}
Anything helps, thank you guys.
Have a good day!
modified 6-May-18 14:51pm.
|
|
|
|
|
Your call to nextInt returns a number in the range [0..5] so you will end up with a number in the range [1..6], so you can never roll an 8 or a 9, as specified in your examples.
To get the highest number you need to write a method which takes two numbers and returns the relevant value. The algorithm for this is fairly straightforward. Compare the two numbers to get the higher number (or either one if they are equal). Multiply the higher number by 10 and add the lower, which gives the "highest" value.
|
|
|
|
|
Hi. For the question below I wrote a code which you can see and it has an unknown error. I appreciate if someone can tell me where the problem is. Thanks.
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
class Solution {
public boolean isSymmetric(TreeNode root) {
boolean flag = false;
if (root == null) return true;
if(root.left == root.right != null)
flag = twoSymmetric(root.left , root.right);
retrun flag;
}
public boolean twoSymmetric(TreeNode left , TreeNode right){
if (left.left.val == right.right.val != null && left.right.val == right.left.val != null) return twoSymmetric(left.left , right.rigth) && twoSymmetric(left.right , right.left);
else return false;
}
}
|
|
|
|
|
It is not clear what your node structure is, but at a guess your code needs modifying to something like:
public boolean twoSymmetric(TreeNode left , TreeNode right){
if (left.val == right.val) {
if (left.left != null && right.right != null) {
if (twoSymmetric(left.left, right.right) {
if (left.right != null && right.left != null) {
return (twoSymmetric(left.right , right.left);
}
}
}
}
return false;
}
|
|
|
|
|
Text files like this:
1.txt :
cronie-anacron::1.4.11::17.el7::x86_64::Friday 05 January 2018 11:13:34 AM IST
2.txt :
accountsservice :: 0.6.40-2ubuntu11.3 :: None :: amd64 :: None
|
|
|
|
|
|
I have some DTOs that are written to be immutable.
private List<Transformation> foo;
... [omitted for brevity]
public List<Transformation> getFoo() {
List<Transformation> bar = new ArrayList<Transformation>(foo.size());
for (Transformation listEntry : foo) {
bar.add(Transformation.of(listEntry));
}
return bar;
}
This works for my current application as I happen to know that the Lists are all ArrayLists.
What if I didn't know that? Is there a way to deep copy the contents of an arbitrary implementation of List without knowing what type that underlying List is?
|
|
|
|
|
As long as ListType is clonable, you can do it as following
bar.add(listEntry.clone());
|
|
|
|
|
I can't seem to figure out what I am doing wrong with my while loop. For some reason it wont execute the loop it just goes on to the next piece of code. please let me know what is wrong with my syntax.
package com.nec;
import java.util.Scanner;
public class Inputs {
private static Scanner s;
private static String grade;
private static Boolean flag;
private static double averageSum;
private static int studentCounter;
private static Double classAverage;
public static void main(String[] args)
{
grade = "";
flag = true;
averageSum = 0;
studentCounter = 0;
While (flag); {
flag = (false);
s = new Scanner (System.in);
System.out.print("Enter your name: ");
String name = s.next();
System.out.print("Enter scores in three subjects: ");
int scores1 = s.nextInt();
int scores2 = s.nextInt();
int scores3 = s.nextInt();
double average = (scores1+scores2+scores3) /3.0;
averageSum = averageSum + average;
studentCounter++;
if (average >= 93) {
grade = "A";
}
if (average >= 90 && average < 93) {
grade = "A-";
}
if (average >= 87 && average < 90) {
grade = "B+";
}
if (average >= 83 && average < 87) {
grade = "B";
}
if (average >= 80 && average < 83) {
grade = "B-";
}
if (average >= 77 && average < 80) {
grade = "C+";
}
if (average >= 73 && average < 77) {
grade = "C";
}
if (average >= 70 && average < 73) {
grade = "C-";
}
if (average >= 67 && average < 70) {
grade = "D+";
}
if (average >= 63 && average < 67) {
grade = "D";
}
if (average >= 60 && average < 63) {
grade = "D-";
}
if (average >= 0 && average < 60) {
grade = "F";
}
System.out.println("\nName: " +name);
System.out.println("Average: " +average);
System.out.println("grade:" +grade);
System.out.println("Do you have another set of scores to compute, enter 1 for yes and 0 for no");
int ans2 = s.nextInt();
if (ans2 == 1) flag = true;
if (ans2 == 0) flag = false;}
classAverage = averageSum / studentCounter;
System.out.println("Class Average is:" +classAverage);
}
private static void While(Boolean flag2) {
}
}
|
|
|
|
|
While (flag); {
flag = (false);
You have a semi-colon after the expression which means that is the end of the while statement.
private static void While(Boolean flag2) {
}
Using While for a method name is bound to cause confusion and possible problems. Do not use names that could be mistaken. And yes, I know it is spelled slightly differently.
|
|
|
|
|
Hi all! I build a JUnit BookTestCase to test the minPrice() method in the BookApp class. The method is to find and return the minimum price of an array of book objects. But the test fails, and it shows "AssertionFailedError: expected: <34.99> but was: <0.0>". I don't know where the problem is, and where the 0.0 comes from. Thanks in advance!
The BookTestCase:
class BookTestCase {
private BookApp obj;
private Book[] book = new Book[5];
@BeforeEach
void setUp() throws Exception {
this.obj = new BookApp();
book[0] = new Book(1, "HTLM", 56.0);
book[1] = new Book(2, "Java", 128.0);
book[2] = new Book(3, "Python", 34.99);
book[3] = new Book(4, "C#", 40.0);
book[4] = new Book(5, "C", 115.5);
}
@Test
void testPopulateBooks() {
Assertions.assertThrows(IllegalArgumentException.class, () -> obj.populateBooks(6));
}
@Test
void testMinPrice() {
assertEquals(34.99, BookApp.minPrice(book), 0.0001);
}
}
The minPrice() in BookApp class:
public class BookApp {
public static double minPrice(Book[] b) {
double min = b[0].getPrice();
for (int i = 1; i < b.length; i++) {
if (b[i].getPrice() < min)
min = b[i].getPrice();
}
return min;
}
}
|
|
|
|