Possible lossy conversion from double to int; Java; Linked List [duplicate]












-3
















This question already has an answer here:




  • What does “possible lossy conversion” mean and how do I fix it?

    1 answer



  • Java JDK - possible lossy conversion from double to int

    2 answers



  • error: incompatible types: possible lossy conversion from double to int

    1 answer




at the moment, I'm exercising with linked list but I have a problem with a code. The code below runs and work, but when I'm trying to add some nodes using a for generating random numbers it gave me this error. Before adding the for the code works and run adding the now as you can see into main. Maybe I missed something. Can someone help me to understand?



P.S. The commented part was the part of the main that I tryed to "upgrade".



import java.util.Random;

class Node {
private int value;
private Node next = null;

public Node(int value) {
this.value = value;
}

public int getValue() { return this.value; }

public Node getNext() { return this.next; }

public void setNext(Node pNext) { this.next = pNext; }

}

public class linked {

private Node head;
private Node tail;
private int size;

public int getSize() { return this.size; }

public void insert (Node ele) {
if (this.head == null) {
this.tail = ele;
this.head = this.tail;
}
else {
this.tail.setNext(ele);
this.tail = ele;
}
this.size++;
}

@Override
public String toString() {
StringBuilder ret = null;
if ((this.head != null) && (this.tail != null)) {

ret = new StringBuilder("[Dimensione: " + this.size
+ ", Head: "
+ this.head.getValue()
+ ", Tail: "
+ this.tail.getValue()
+ "] Elementi: ");
Node tmp = this.head;
while (tmp != null) {
ret.append(tmp.getValue() + " -> ");
tmp = tmp.getNext();
}
ret.append("/");
}
return ret == null ? "[null]" : ret.toString();
}

public static void main (String args)
{
linked ll = new linked();
System.out.println(ll);

for(int i=0; i<15; i++) {
Random rand = new Random();
double pazz = rand.nextInt(50) + 1;
ll.insert(new Node(pazz));
}
/*
ll.insert(new Node(10));
System.out.println(ll);

ll.insert(new Node(25));
System.out.println(ll);

ll.insert(new Node(12));
System.out.println(ll);

ll.insert(new Node(20));
System.out.println(ll);
*/
}
}









share|improve this question















marked as duplicate by Jacob G. java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 3





    1 - declare pazz as int. 2 - Move new Random outside the loop

    – zlakad
    Jan 2 at 19:21






  • 1





    Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

    – Andreas
    Jan 2 at 19:22
















-3
















This question already has an answer here:




  • What does “possible lossy conversion” mean and how do I fix it?

    1 answer



  • Java JDK - possible lossy conversion from double to int

    2 answers



  • error: incompatible types: possible lossy conversion from double to int

    1 answer




at the moment, I'm exercising with linked list but I have a problem with a code. The code below runs and work, but when I'm trying to add some nodes using a for generating random numbers it gave me this error. Before adding the for the code works and run adding the now as you can see into main. Maybe I missed something. Can someone help me to understand?



P.S. The commented part was the part of the main that I tryed to "upgrade".



import java.util.Random;

class Node {
private int value;
private Node next = null;

public Node(int value) {
this.value = value;
}

public int getValue() { return this.value; }

public Node getNext() { return this.next; }

public void setNext(Node pNext) { this.next = pNext; }

}

public class linked {

private Node head;
private Node tail;
private int size;

public int getSize() { return this.size; }

public void insert (Node ele) {
if (this.head == null) {
this.tail = ele;
this.head = this.tail;
}
else {
this.tail.setNext(ele);
this.tail = ele;
}
this.size++;
}

@Override
public String toString() {
StringBuilder ret = null;
if ((this.head != null) && (this.tail != null)) {

ret = new StringBuilder("[Dimensione: " + this.size
+ ", Head: "
+ this.head.getValue()
+ ", Tail: "
+ this.tail.getValue()
+ "] Elementi: ");
Node tmp = this.head;
while (tmp != null) {
ret.append(tmp.getValue() + " -> ");
tmp = tmp.getNext();
}
ret.append("/");
}
return ret == null ? "[null]" : ret.toString();
}

public static void main (String args)
{
linked ll = new linked();
System.out.println(ll);

for(int i=0; i<15; i++) {
Random rand = new Random();
double pazz = rand.nextInt(50) + 1;
ll.insert(new Node(pazz));
}
/*
ll.insert(new Node(10));
System.out.println(ll);

ll.insert(new Node(25));
System.out.println(ll);

ll.insert(new Node(12));
System.out.println(ll);

ll.insert(new Node(20));
System.out.println(ll);
*/
}
}









share|improve this question















marked as duplicate by Jacob G. java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 3





    1 - declare pazz as int. 2 - Move new Random outside the loop

    – zlakad
    Jan 2 at 19:21






  • 1





    Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

    – Andreas
    Jan 2 at 19:22














-3












-3








-3









This question already has an answer here:




  • What does “possible lossy conversion” mean and how do I fix it?

    1 answer



  • Java JDK - possible lossy conversion from double to int

    2 answers



  • error: incompatible types: possible lossy conversion from double to int

    1 answer




at the moment, I'm exercising with linked list but I have a problem with a code. The code below runs and work, but when I'm trying to add some nodes using a for generating random numbers it gave me this error. Before adding the for the code works and run adding the now as you can see into main. Maybe I missed something. Can someone help me to understand?



P.S. The commented part was the part of the main that I tryed to "upgrade".



import java.util.Random;

class Node {
private int value;
private Node next = null;

public Node(int value) {
this.value = value;
}

public int getValue() { return this.value; }

public Node getNext() { return this.next; }

public void setNext(Node pNext) { this.next = pNext; }

}

public class linked {

private Node head;
private Node tail;
private int size;

public int getSize() { return this.size; }

public void insert (Node ele) {
if (this.head == null) {
this.tail = ele;
this.head = this.tail;
}
else {
this.tail.setNext(ele);
this.tail = ele;
}
this.size++;
}

@Override
public String toString() {
StringBuilder ret = null;
if ((this.head != null) && (this.tail != null)) {

ret = new StringBuilder("[Dimensione: " + this.size
+ ", Head: "
+ this.head.getValue()
+ ", Tail: "
+ this.tail.getValue()
+ "] Elementi: ");
Node tmp = this.head;
while (tmp != null) {
ret.append(tmp.getValue() + " -> ");
tmp = tmp.getNext();
}
ret.append("/");
}
return ret == null ? "[null]" : ret.toString();
}

public static void main (String args)
{
linked ll = new linked();
System.out.println(ll);

for(int i=0; i<15; i++) {
Random rand = new Random();
double pazz = rand.nextInt(50) + 1;
ll.insert(new Node(pazz));
}
/*
ll.insert(new Node(10));
System.out.println(ll);

ll.insert(new Node(25));
System.out.println(ll);

ll.insert(new Node(12));
System.out.println(ll);

ll.insert(new Node(20));
System.out.println(ll);
*/
}
}









share|improve this question

















This question already has an answer here:




  • What does “possible lossy conversion” mean and how do I fix it?

    1 answer



  • Java JDK - possible lossy conversion from double to int

    2 answers



  • error: incompatible types: possible lossy conversion from double to int

    1 answer




at the moment, I'm exercising with linked list but I have a problem with a code. The code below runs and work, but when I'm trying to add some nodes using a for generating random numbers it gave me this error. Before adding the for the code works and run adding the now as you can see into main. Maybe I missed something. Can someone help me to understand?



P.S. The commented part was the part of the main that I tryed to "upgrade".



import java.util.Random;

class Node {
private int value;
private Node next = null;

public Node(int value) {
this.value = value;
}

public int getValue() { return this.value; }

public Node getNext() { return this.next; }

public void setNext(Node pNext) { this.next = pNext; }

}

public class linked {

private Node head;
private Node tail;
private int size;

public int getSize() { return this.size; }

public void insert (Node ele) {
if (this.head == null) {
this.tail = ele;
this.head = this.tail;
}
else {
this.tail.setNext(ele);
this.tail = ele;
}
this.size++;
}

@Override
public String toString() {
StringBuilder ret = null;
if ((this.head != null) && (this.tail != null)) {

ret = new StringBuilder("[Dimensione: " + this.size
+ ", Head: "
+ this.head.getValue()
+ ", Tail: "
+ this.tail.getValue()
+ "] Elementi: ");
Node tmp = this.head;
while (tmp != null) {
ret.append(tmp.getValue() + " -> ");
tmp = tmp.getNext();
}
ret.append("/");
}
return ret == null ? "[null]" : ret.toString();
}

public static void main (String args)
{
linked ll = new linked();
System.out.println(ll);

for(int i=0; i<15; i++) {
Random rand = new Random();
double pazz = rand.nextInt(50) + 1;
ll.insert(new Node(pazz));
}
/*
ll.insert(new Node(10));
System.out.println(ll);

ll.insert(new Node(25));
System.out.println(ll);

ll.insert(new Node(12));
System.out.println(ll);

ll.insert(new Node(20));
System.out.println(ll);
*/
}
}




This question already has an answer here:




  • What does “possible lossy conversion” mean and how do I fix it?

    1 answer



  • Java JDK - possible lossy conversion from double to int

    2 answers



  • error: incompatible types: possible lossy conversion from double to int

    1 answer








java math linked-list nodes adt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 20:38









PoByBolek

2,77521119




2,77521119










asked Jan 2 at 19:16









Giovanni GiampaoloGiovanni Giampaolo

3115




3115




marked as duplicate by Jacob G. java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Jacob G. java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 19:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 3





    1 - declare pazz as int. 2 - Move new Random outside the loop

    – zlakad
    Jan 2 at 19:21






  • 1





    Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

    – Andreas
    Jan 2 at 19:22














  • 3





    1 - declare pazz as int. 2 - Move new Random outside the loop

    – zlakad
    Jan 2 at 19:21






  • 1





    Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

    – Andreas
    Jan 2 at 19:22








3




3





1 - declare pazz as int. 2 - Move new Random outside the loop

– zlakad
Jan 2 at 19:21





1 - declare pazz as int. 2 - Move new Random outside the loop

– zlakad
Jan 2 at 19:21




1




1





Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

– Andreas
Jan 2 at 19:22





Why did you declare pazz as a double, when you assign it an int value, and want to pass it to a method expecting int? Change declaration to int.

– Andreas
Jan 2 at 19:22












1 Answer
1






active

oldest

votes


















1














double pazz = rand.nextInt(50) + 1;


Here you set pazz as double. You should set it to int instead.






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    double pazz = rand.nextInt(50) + 1;


    Here you set pazz as double. You should set it to int instead.






    share|improve this answer




























      1














      double pazz = rand.nextInt(50) + 1;


      Here you set pazz as double. You should set it to int instead.






      share|improve this answer


























        1












        1








        1







        double pazz = rand.nextInt(50) + 1;


        Here you set pazz as double. You should set it to int instead.






        share|improve this answer













        double pazz = rand.nextInt(50) + 1;


        Here you set pazz as double. You should set it to int instead.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 19:22









        Stalemate Of TuningStalemate Of Tuning

        542315




        542315

















            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas