#java #loops
Вопрос:
ВОТ МОИ КОДЫ
Я ПОПРОБОВАЛ МЕТОД 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 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 ".");
}
}
}Или, может быть, я просто ошибаюсь в этих скобках, можете ли вы помочь мне определить, в чем проблема?
Я новичок в Java
Ответ №1:
Попробуйте Main()
снова вызвать метод с помощью Intent
или вы можете просто попробовать позвонить Main()
, не используя Intent
сначала, чтобы сэкономить место в строке…