Home > Back-end >  JAVA sprout new for help
JAVA sprout new for help

Time:10-07

CodePudding user response:

Much more code or learn what to write, remember junction post
 
import java.util.ArrayList;
Import the Java. Util. HashMap;
Import the Java. Util. List;
import java.util.Map;
Import the Java. Util. Set;

Public class Circle {
Private Map The map=new HashMap<> (a);

Public Circle () {
super();
InitCircle ();
}
Public void initCircle () {
for(int i=1; i<=50; I++) {
The map. The put (I, Math. PI * I * I);
}
}
Public Map The getMap () {
Return the map;
}
Public List GetRad () {
List List=new ArrayList<> (a);
Return null if (map. IsEmpty ());
Set Keys=map. The keySet ();
For (Integer key: keys) {
List. The add (key);
}
return list;
}
Public static void main (String [] args) {
Circle cir=new Circle ();
List List=cir. GetRad ();
//test
For (Integer rad: list) {
if(! List. IsEmpty ()) {
Double area=cir. The getMap (). The get (rad);
System. Out. Println (" area: "+ area);
}
}
}
}

CodePudding user response:

1/f, reference source is a ghost reply:
code still have to learn what to write more, and remember to post the
 
import java.util.ArrayList;
Import the Java. Util. HashMap;
Import the Java. Util. List;
import java.util.Map;
Import the Java. Util. Set;

Public class Circle {
Private Map The map=new HashMap<> (a);

Public Circle () {
super();
InitCircle ();
}
Public void initCircle () {
for(int i=1; i<=50; I++) {
The map. The put (I, Math. PI * I * I);
}
}
Public Map The getMap () {
Return the map;
}
Public List GetRad () {
List List=new ArrayList<> (a);
Return null if (map. IsEmpty ());
Set Keys=map. The keySet ();
For (Integer key: keys) {
List. The add (key);
}
return list;
}
Public static void main (String [] args) {
Circle cir=new Circle ();
List List=cir. GetRad ();
//test
For (Integer rad: list) {
if(! List. IsEmpty ()) {
Double area=cir. The getMap (). The get (rad);
System. Out. Println (" area: "+ area);
}
}
}
}

if(! Lest) can you explain it

CodePudding user response:

Is whether the list stored key is empty, avoid abnormal,

CodePudding user response:

Is this meaning?
The code is as follows:
Package com;

Import the Java. Text. DecimalFormat;
Import the Java. Util. HashMap;
Import the Java. Util. Iterator;
import java.util.Map;
Import the Java. Util. Set;
@ SuppressWarnings (" all ")
Public class Circle {
Public static void main (String [] args) {
//create a Map object
The Map m=new HashMap ();
//define "area" variable
Double queue=0;
//circulation calculated circle area, and inserted into the Map collections
For (int I=1; I & lt;=50; I++) {
The queue=Math. PI * I * I;
M.p ut (I, queue);
}
//create "access to two decimal places" object
DecimalFormat df=new DecimalFormat (" 00 ");
//get the Map Key value of a set of
Set S=m.k eySet ();
//the value of loop output Map values
For (Integer key: s) {
A Double value=https://bbs.csdn.net/topics/(Double) m.g et (key);
System. The out. Println (" Map collections in the Key value is: "+ Key +" value value is: "+ df. The format (value));
}
}
}
  • Related