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

我如何通过回答是或否来重复这个程序?

毋弘光
2023-03-14

这是我的密码

我尝试了DO WHILE方法,但它也不起作用:

import java.util.Scanner;
import java.io.Console;

public class Main
{
    public static void main(String[] args) {
    String name;
    int choice;
    int time;
    Console cons = System.console();
    if (cons==null)
    {

        System.out.println("");
        return;
    }

我在这里开始做,但它不起作用

    name = cons.readLine("Enter your Name: ");
    Scanner scn = new Scanner(System.in);
    
    System.out.println("\nMenu");
    System.out.println("\n[1] Network Engineer\n[2] Software Engineer\n[3] Full Stack Developer\n[4] Technical Support");
    
    
    System.out.print("\nEnter your job(Choose a number from the menu): ");
    choice = scn.nextInt();
    System.out.print("Enter no. of hours present at work: " );
    time = scn.nextInt();
    
    
    if (choice == 1)
    {
        int gsalary = 1200*time;
        int nsalary = gsalary - (gsalary * 12 / 100);
        
        cons.printf("\nHello %s!\n", name);
        System.out.println("Your job salary as a Network Engineer is 1200 per hour.");
        System.out.println("Your gross salary for this week is "+gsalary+".");
        System.out.println("Your net salary for this weeks is "+nsalary+".");
    }
    
    if (choice == 2)
    {
        int gsalary = 800*time;
        int nsalary = gsalary - (gsalary * 12 / 100);
        
        cons.printf("\nHello %s!\n", name);
        System.out.println("Your job salary as a Network Engineer is 800 per hour.");
        System.out.println("Your gross salary for this week is "+gsalary+".");
        System.out.println("Your net salary for this weeks is "+nsalary+".");
    }
    
    if (choice == 3)
    {
        int gsalary = 600*time;
        int nsalary = gsalary - (gsalary * 12 / 100);
        
        cons.printf("\nHello %s!\n", name);
        System.out.println("Your job salary as a Network Engineer is 600 per hour.");
        System.out.println("Your gross salary for this week is "+gsalary+".");
        System.out.println("Your net salary for this weeks is "+nsalary+".");
    }
    
    if (choice == 4)
    {
        int gsalary = 500*time;
        int nsalary = gsalary - (gsalary * 12 / 100);
        
        cons.printf("\nHello %s!\n", name);
        System.out.println("Your job salary as a Network Engineer is 500 per hour.");
        System.out.println("Your gross salary for this week is "+gsalary+".");
        System.out.println("Your net salary for this weeks is "+nsalary+".");
    }
}

}或者可能我只是把那些括号搞错了,你能帮我确定是什么问题吗?我是Java新手

共有1个答案

呼延运恒
2023-03-14

尝试使用intent再次调用main()方法,或者您可以先尝试调用main(),而不使用intent,以节省一些行空间...

 类似资料:
  • 写一个函数均衡器(w1,w2),它包含两个不同长度的单词w1和w2。函数应该返回重复的较小单词,直到它达到长单词的长度

  • 我举一个url为例: 您可以在浏览器中看到它。 现在我想下载它。我试过: 失败,获取“错误”图片。 失败,获取“错误”图片。 失败了,得到了一张静态照片,我是说,只有一帧。 那么我该怎么做呢?

  • 不幸的是,这是TLES。由于我使用递归调用,所以我并不真的认为我遇到了重叠的子问题。 有办法让我记住我的解决方案吗?如果没有,为什么?

  • 我被困在第2天:hackerrank上的操作员问题。任务如下:给定一顿饭的餐费(一顿饭的基本成本)、小费百分比(餐费的百分比作为小费添加)和税收百分比(餐费的百分比作为税收添加),查找并打印餐费的总成本。将结果四舍五入到最接近的整数。 这是我的代码: 截图

  • 此代码不断返回 即使选择变量是正确的。我应该进行哪些编辑以使其打印总成本?

  • 我想知道是否有标志和参数可以通过单击通知托盘中的推送通知来告诉我用户是否启动了活动/应用程序。 我在 C2DM 接收器中的代码.java 我试着设定 但当该应用程序启动时,其意图中没有额外的内容。 我的mainactivity的onCreate函数中的代码 我得到的输出是onCreate - bundle没有额外的内容。所以多余的部分没有通过。 那么还有其他方法吗?在iOS中很容易

  • 我被困在第二天:黑客银行的操作员问题。任务如下: 给定一顿饭的价格(一顿饭的基本成本)、小费百分比(加在小费上的餐费百分比)和税百分比(加在税上的餐费百分比),查找并打印这顿饭的总成本。将结果四舍五入到最接近的整数。 这是我的代码: 截图

  • 考虑以下程序: (编译器资源管理器) GCC和Clang的各种版本都可以接受它,但MSVC不能接受它,因为MSVC编译失败,出现错误消息 第一条错误消息向我暗示了ODR违规--但如果这个程序是格式不良的NDR,我需要帮助理解为什么会这样。我已经检查了标准草案中的temp.over.link,但我不相信我对它的解释是正确的。根据我的理解,程序是可以的,因为这些函数模板有不同的签名。 在不太可能的情况