I'm looking for a way to create a table that looks like this:
This is what my code looks like so far:
public class YourName {
public static void main(String[] args) {
System.out.println("Tecken \tGrundamne \tAtomnummer \tAtommassa \tMasstal");
System.out.println("==================================================================");
System.out.print("Ag \tSilver");
int agNumber = 47;
float agMass = 107.8682f;
float agMasstal = Math.round (agMass - agNumber);
System.out.print(agNumber);
System.out.print(agMass);
System.out.print(agMasstal);
System.out.print("Au \tGuld");
int auNumber = 79;
float auMass = 196.96654f;
float auMasstal = Math.round (auMass - auNumber);
System.out.print(auNumber);
System.out.print(auMass);
System.out.print(auMasstal);
System.out.print("C \tKol");
int cNumber = 6;
float cMass = 12.01f;
float cMasstal = Math.round (cMass - cNumber);
System.out.print(cNumber);
System.out.print(cMass);
System.out.print(cMasstal);
}
}
3 questions:
- How can I get each print on a new line? As you can tell from the image, I want to have the last line as C [tab] Kol [tab] 6 [tab] 12.01 [tab] 6, for instance.
- How can I make tabs between each print?
- When I compile and run, it seems that the
Math.round
includes a single decimal, and I would like it to be without, as in the attached image.
Please do not mind the Swedish headings and words.
Thanks a lot!