• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to make this number point?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
========
public class TestTikus {
public static void main (String[] args) {
Tikus t = new Tikus();

t.setWeight(10);
System.out.println("Tikus ni berat:"+ t.getWeight());


}
}
=========
public class Tikus {
private float weight;
public float getWeight() {
return weight;
}

public void setWeight(float newWeight) {
if (newWeight > 0) {
weight = newWeight;
}
}
}
=======
output:10.0


how can i get the output....let say..i want 10.3
how can i do that?

and..how can i get input from user?
in others words,the programme prompt and ask the user to give the weight

thanks for helping me~
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand the first part of your question. The program is just printing whatever value you send to the method.

In order to get input from the user, you can use java.util.Scanner.
[ October 09, 2006: Message edited by: Keith Lynn ]
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"javac java",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by javac java:
========
public class TestTikus {
public static void main (String[] args) {
Tikus t = new Tikus();

t.setWeight(10);
System.out.println("Tikus ni berat:"+ t.getWeight());


}
}
=========
public class Tikus {
private float weight;
public float getWeight() {
return weight;
}

public void setWeight(float newWeight) {
if (newWeight > 0) {
weight = newWeight;
}
}
}
=======
output:10.0


how can i get the output....let say..i want 10.3
how can i do that?

and..how can i get input from user?
in others words,the programme prompt and ask the user to give the weight

thanks for helping me~

 
MV Krishna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use BufferedReader to read the input from the command line.

Example:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic