如何通过回答Yes或No来重复此程序?



以下是我的代码

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

我应该做Case break还是坚持做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 Engineern[2] Software Engineern[3] Full Stack Developern[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+".");
}
}
或者可能是我被括号弄错了,你能帮我确定问题是什么吗?I am new in Java

尝试使用Intent再次调用Main()方法,或者您可以尝试调用Main()而不首先使用Intent以节省一些行空间…

相关内容

最新更新