簡體   English   中英

如何寫合理的圈子?

[英]How to writing rational at circle?

這個程序是一個菜單。(請不要懷疑為什么這個名字)

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package menü.rendszer;
import java.util.Scanner;
/**
 *
 * @author Apa---2016
 */
public class MenüRendszer{

    /**
     * @param args the command line arguments
     */
public static void main(String[] args){
Scanner beolv;
beolv=new Scanner(System.in);
boolean y=false;
do{
System.out.println("Válassz egy síkidomot!(Choose one plane figure!)");
System.out.println("(1)Téglalap(Retangle)");
System.out.println("(2)Kör(Circle)");
System.out.println("(3)Háromszög(Triangle)");
System.out.println("(4)Rombusz(Rhombus)");
System.out.print("Számkód:(Number code");
int x=0;
x=beolv.nextInt();
switch(x){
case 1:
    System.out.println("A kiválasztott síkidom:Téglalap(The choosed plane figure:Retangle)");
    int a=0;
    System.out.print("a=");
    a=beolv.nextInt();
    int b=0;
    System.out.print("b=");
    b=beolv.nextInt();
    int K=0;
    K=2*(a+b);
    int T=0;
    T=a*b;
    System.out.println("Kerülete(Perimeter):"+K);
    System.out.println("Területe(Area):"+T);
    System.out.println();
    break;
case 2:
    System.out.println("A kiválasztott síkidom:Kör(The choosed plane figure:Circle)");
    int R=0;
    System.out.print("R=");
    R=beolv.nextInt();
    K=0;
    T=0;
    K=(int)(2*R*3.14);
    T=(int)(R*R*3.14);
    System.out.println("Kerülete(Perimeter):"+K);
    System.out.println("Területe(Area):"+T);
    System.out.println();
    break;
case 3:
    System.out.println("A kiválasztott síkidom:(Derékszögű)Háromszög(The choosed plane figure:(Right)Triangle)");
    K=0;
    T=0;
    System.out.print("a=");
    a=beolv.nextInt();
    System.out.print("b=");
    b=beolv.nextInt();
    int c=0;
    c=(int) Math.sqrt(a*a+b*b);
    K=a+b+c;
    T=a*b/2;
    System.out.println("Kerülete(Perimeter):"+K);
    System.out.println("Területe(Area):"+T);
    System.out.println();
    break;
case 4:
    System.out.println("A kiválasztott síkidom:Rombusz(The choosed plane figure:Rhombus)");
    K=0;
    T=0;    
    int e=0;
    int f=0;
    System.out.print("e=");
    e=beolv.nextInt();
    System.out.print("f=");
    f=beolv.nextInt();
    K=e*e+f*f/4;
    T=e*f/2;
    System.out.println("Kerülete(Perimeter):"+K);
    System.out.println("Területe(Area):"+T);
    System.out.println();
    break;
default:y=false;break;
}
}
while(!y);
}
}

你看到圓圈了嗎? 我測試過,例如R = 10原來的preimeter = 62.8,但是輸出僅為62。 第二個問題。 如何保持默認開關? (我希望你能理解,因為我不會說英語。)(我是匈牙利。)

一個hibádaz volt,一個hoz az y -ta程序,elejénhamisraállítottad,是default -ban。 哈AZelejénigazzal kezdesz,ES addigismételszamíg y igaz,akkor約爾霧működni。

您的問題是您將y初始化為false, default將其設置為false。 如果您從true開始,並在y為true時循環,則可以正常工作。

 public static void main(String[] args) {
    Scanner beolv;
    beolv = new Scanner(System.in);
    boolean y = true;
    do {
        System.out.println("Válassz egy síkidomot!");
        System.out.println("(1) Téglalap");
        System.out.println("(2) Kör");
        System.out.println("(3) Háromszög");
        System.out.println("(4) Rombusz");
        System.out.print("Számkód: ");
        int x;
        x = beolv.nextInt();
        switch (x) {
            case 1:
                System.out.println("A kiválasztott síkidom: Téglalap");
                double a;
                System.out.print("a=");
                a = beolv.nextInt();
                double b;
                System.out.print("b=");
                b = beolv.nextInt();
                double K;
                K = 2 * (a + b);
                double T;
                T = a * b;
                System.out.println("Kerülete(Perimeter):" + K);
                System.out.println("Területe(Area):" + T);
                System.out.println();
                break;
            case 2:
                System.out.println("A kiválasztott síkidom: Kör");
                double R;
                System.out.print("R=");
                R = beolv.nextInt();
                K = (2 * R * 3.14);
                T = (R * R * 3.14);
                System.out.println("Kerülete:" + K);
                System.out.println("Területe:" + T);
                System.out.println();
                break;
            case 3:
                System.out.println("A kiválasztott síkidom: (Derékszögű) Háromszög");
                System.out.print("a=");
                a = beolv.nextInt();
                System.out.print("b=");
                b = beolv.nextInt();
                double c;
                c = Math.sqrt(a * a + b * b);
                K = a + b + c;
                T = a * b / 2;
                System.out.println("Kerülete:" + K);
                System.out.println("Területe:" + T);
                System.out.println();
                break;
            case 4:
                System.out.println("A kiválasztott síkidom: Rombusz");
                double e;
                double f;
                System.out.print("e=");
                e = beolv.nextInt();
                System.out.print("f=");
                f = beolv.nextInt();
                K = e * e + f * f / 4;
                T = e * f / 2;
                System.out.println("Kerülete:" + K);
                System.out.println("Területe:" + T);
                System.out.println();
                break;
            default:
                y = false;
                break;
        }
    }
    while (y); // Addig ismételje amíg y igazra van állítva, a default hamisra rakja és kilép a program.
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM