我正在尝试获取此方法以使温度正确打印但卡住了

时间:2019-10-23 22:01:05

标签: java methods

public static void temperatures (int minTemp, int maxTemp, int increment ){
int F = 0; // Fahrenheit
double C, K; //Celsius, Kelvin

for ( minTemp = 0; minTemp <= maxTemp ; minTemp++){
   C = ( F - 32.0) * 5.0/9.0;
      K = C + 273.15;
    increment++;
System.out.println( temperatures );
}
}//end temperatures  
  

//这是应该打印的

     

//华氏摄氏温度开尔文

     

// ----- | ------- | ------

     

// 10 | -12.22 | 260.93

它还会循环10次,因此华氏温度会达到10-100等,然后停止运行,因此我认为for循环需要循环10次而不是循环,但我不太确定,因为我什么都不能打印

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

<div
    #wrapper
  id="wrapper"
  [style.cursor]="this.startOfPan ? 'grabbing' : isInPanningMode ? 'grab' : 'default'"
  (mousemove)="canvasLocation = [$event.clientX, $event.clientY]"
>
  <canvas
      #outerCanvas id="outer-canvas"
  ></canvas>
  <div
    id="graph-wrapper"
    [ngStyle]="{
        'top.px': graphDrawer.config.lastValueYMargin,
        'left.px': graphDrawer.origin[0]
      }"
  >
    <div id="chart-title">{{chart.title}} - {{shortGuid}}</div>

    <canvas
        #innerCanvas id="inner-canvas"
      (mousemove)="handleMouseMove($event, Regions.graph)"
      (mousedown)="handleMouseDown()"
      (mousewheel)="handleMouseWheel($event)"
      [ngStyle]="{
        'border-left-width.px': !config.drawAxes ? 0 : !chart.yAxisRight ? config.axisWidth : 0,
        'border-right-width.px': !config.drawAxes ? 0 : chart.yAxisRight ? config.axisWidth : 0,
        'border-bottom-width.px': !config.drawAxes ? 0 : chart.xAxisTop ? 0 : config.axisWidth,
        'border-top-width.px': !config.drawAxes ? 0 : !chart.xAxisTop ? 0 : config.axisWidth
      }"
    ></canvas>
    <div
      id="selection" *ngIf="!!selection"
      [ngStyle]="{
      'top.px': selectionRect.y,
      'left.px': selectionRect.x,
      'height.px': selectionRect.height,
      'width.px': selectionRect.width
      }"
    ></div>
  </div>
  <div
    id="x-axis-hover" class="axis-hover"
    (mousemove)="handleMouseMove($event, Regions.xGutter)"
    (mouseleave)="didLeaveGutter()"
    (mousedown)="handleMouseDown()"
    (mousewheel)="handleMouseWheel($event)"
    [ngStyle]="{
      'top.px': graphDrawer.graphHeight,
      'left.px': !chart.yAxisRight ? graphDrawer.yAxisGutterWidth : graphDrawer.config.lastValueXMargin,
      'height.px': graphDrawer.xAxisGutterHeight,
      'width.px': config.drawAxes ? graphDrawer.graphWidth : graphDrawer.plottableWidth + 1,
      'backgroundColor': mouseLocation.region === 'xGutter' ? 'rgb(105,105,105,0.3)' : 'transparent'
    }"
  ></div>
  <div
    id="y-axis-hover" class="axis-hover"
    (mousemove)="handleMouseMove($event, Regions.yGutter)"
    (mouseout)="didLeaveGutter()"
    (mousedown)="handleMouseDown()"
    (mousewheel)="handleMouseWheel($event)"

    [ngStyle]="{
      'top.px': config.drawAxes ? 0 : graphDrawer.config.lastValueYMargin - 1,
      'left.px': !chart.yAxisRight ? 0 : graphDrawer.plottableWidth + graphDrawer.config.lastValueXMargin,
      'height.px': config.drawAxes ? graphDrawer.graphHeight + config.axisWidth : graphDrawer.plottableHeight + 2,
      'width.px': graphDrawer.yAxisGutterWidth,
      'backgroundColor': mouseLocation.region === 'yGutter' ? 'rgb(105,105,105,0.3)' : 'transparent'
    }"
  ></div>
</div>

输出:

public class BinarySearchDemo {
    public static void main(String[] args) {
        temperatures(0, 100, 10);
    }
    public static void temperatures(int minTemp, int maxTemp, int increment) {
        double c, k; // Celsius, Kelvin
        for (int f =minTemp;f <= maxTemp; f+=increment) {
            c = (f - 32.0) * 5.0 / 9.0;
            k = c + 273.15;
            System.out.printf("%3d|%8.2f|%8.2f\n",f,c,k);
        }
    }// end temperatures
}