Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

printing method

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would be the difference between the next two types when printing in java?

v3.print("v3");
System.out.println("v3 = " + v3);

Thank you.

Ricardo.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
v3.print() is not part of the core API. It's a method you wrote, or your instructor did, or it's from some thirdparty library. Since none of us know anything about what v3 is, we cannot answer that.
 
Ricardo De Jesus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jeff, the entire code is as follows:



I have omitted v3.print("v3"); with comments // on line 15 in order to get its output, it turned out to be:

v1 = ( 4.00000e+00, 5.00000e+00, 6.00000e+00)^T
v2 = ( 9.00000e+00, 8.00000e+00, 7.00000e+00, 4.00000e+00)^T
v3 = [1.0, 1.0, 1.0, 1.0, 1.0]
a = ( 5.00000e+00, 2.00000e+00, -9.00000e+00)^T
b = [5.0]
c = [9.0]

It can be seen in the output, that the format of v3 with System.out.println("v3 = " + v3); as indicated on line 16, is different as to the digits compared to v1 and v2. What would be the impact of having v3 in this way in comparison to v1 and v2? And also, what is the meaning of the symbols ^T, in the output, at the end of v1, v2 and a?

Best regards.

Ricardo.
 
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like a duplicate of this thread. Please do not duplicate discussions.

That is not the entire code. Without seeing the Vector class, nobody can understand what is happening.
 
Ricardo De Jesus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the vector class:



The question is from myself, I am studying to understand how to print out vectors and calculate scalar products between vectors. This Vector class has been provided to me from my instructor, there is no other source from books at the moment.

I appreciate your help.
 
Campbell Ritchie
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can see the print method prints the text you pass to it, followed by the i elements of the array, each occupying 12 spaces with 5 after the decimal place, then ^T. If you don’t put values into the array, then they default to 0, displayed as 0.00000.
Does your Vector class have a toString() method? If you try System.out.println(v); you will there invoke the unoverridden version from Object.
 
Ricardo De Jesus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response, it really helped me.
 
Campbell Ritchie
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic