当前位置: 首页 > 知识库问答 >
问题:

我不知道我的代码有什么问题

孔硕
2023-03-14

我拿不到输出。。有人能帮我得到输出吗

下面给出了程序运行的示例(注意:下面的粗体文本是用户输入的输入):

输入三角形的三条边

import java.util.*;

public class right_angle_triangle {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        char ch = 'y';
        while(ch == 'y'){
        System.out.print("Enter the three sides of a triangle> ");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a>0 && b>0 && c>0){
            int a1 = a*a;
            int b1 = b*b;
            int c1 = c*c;
            if(c1== a1+b1 || b1==a1+c1 || a1==b1+c1){
                count++;
                System.out.println("Yes, this is a right-angled triangle.");
            }
            else {
                System.out.println("No, this is not a right-angled triangle.");
            }  
        }
        else{
            System.out.print("No, this is not a right-angled triangle.");
        }          
                System.out.print("Do you want to continue? (y/n) > ");
                ch = sc.next().charAt(0);

                
System.out.println("The total number of right-angled triangle = "+count);
            }
            
        }
        
        }
    

共有1个答案

戴鸿羲
2023-03-14

你能解释一下你真正想要的是什么吗?因为我测试过它会打印输出:

Enter the three sides of a triangle> 5
3
4
Yes, this is a right-angled triangle.
Do you want to continue? (y/n) > 

好的,我想,我明白你的情况下有什么问题,你必须按Enter每次给输入

 类似资料:
  • 我拿不到输出。。有人能帮我得到输出吗 下面给出了程序运行的示例(注意:下面的粗体文本是用户输入的输入): 进入三角形的三个边

  • 抱歉,如果不允许这样做。这是我第一次问问题。无论如何,我应该实现一个程序,根据文本读取等级。 “实施一个程序,根据以下内容计算理解某些文本所需的大致年级水平。文本:恭喜!今天是你的一天。你要去很棒的地方!你走了,走了!3 年级 在完成代码之后。每次我编译它时,它都会给我一个异常,即我除以零。几乎就像在我要求用户输入文本后,它根本不被读取,字母计数保持在零。我不知道如何绕过它。下面是我导入java.

  • 如果参数的类型是int或float,函数应该返回>函数输入的绝对值。 否则,函数应返回“nope” 我已经完成了第一个任务,但我认为我已经完成了任务

  • 给定一个0和1的数组,我们最多可以将K个值从0更改为1。 返回仅包含1的最长(连续)子数组的长度。 例1: 例2: 注: https://leetcode.com/problems/max-consecutive-ones-iii/ 这是问题链接。在第一个测试用例中,我得到了输出9,但应该是6。我不知道哪里出了问题?

  • > 控制器 } 服务 -板 > 原因:java。lang.IllegalArgumentException:给定的id不能为null!位于组织。springframework。util。明确肯定组织中的notNull(Assert.java:201)。springframework。数据jpa。存储库。支持简单Parepository。java上的deleteById(SimpleJpaRepos

  • 作为一名链表数据结构的学习者,我正在练习Leetcode问题“反向链表”,我有自己的解决方案,但不知道为什么它是错误的,有专家可以分享一些指导吗?真的很感激! Leetcode问题: 反转单链接列表。 例: 输入:1- 输出: 5- 我的代码: 然而,上述解决方案是错误的,但可以通过在“temp.next=prev”和“head=head.next”之间切换位置进行纠正,如下所示: 对我来说,切换