简体   繁体   English

Java,使用Loop询问某事重复了多少次

[英]Java, using Loop ask how many times something was repeated

string name;
string DOB;
int hours, status;
int countworkers = 0;
       for (int s = 0; s < number; s++)
  System.out.print("Enter the amount of worker: ");
       int number = sc.nextInt();


     System.out.print("name: ");
           name = sc.next();

           System.out.print("id number: ");
           id = sc.next();

           System.out.print("hours worked: ");
           hour = sc.nextInt();

           System.out.print("What is their Status: fulltimeHome, fulltimeonsite parttimehome, parttimeonsite");
           status = sc.next();
           switch (status) {
case "parttime":
    System.out.println("pay  " + 3465 ) ; 
    break;
case "fulltime":
    System.out.println("pay  " + (hours * 500) ) ; 
    break;

[NOTE: this isn't the full code, I removed the last two case] My code is using the for-loop. [注意:这不是完整的代码,我删除了最后两个案例] 我的代码使用了 for 循环。 How can I get my program to calculate in total the people that enter they are at home workers (fulltimeHome, parttime home) and those who are working on site (fulltimeonsite, parttimeonsite).我怎样才能让我的程序计算进入的人的总数,他们是在家工作的人(fulltimeHome、parttime home)和在现场工作的人(fulltimeonsite、parttimeonsite)。

Have 2 variables onSite and homeWorkers for example and in the correct cases add 1 to the correct one.例如,有 2 个变量 onSite 和 homeWorkers,在正确的情况下将 1 添加到正确的变量中。

int onSite = 0, homeWorkers = 0;

and

case "parttime":
    System.out.println("pay  " + 3465 ) ; 
    onSite ++;
    break;
case "fulltime":
    System.out.println("pay  " + (hours * 500) ) ; 
    onSite ++;
    break;
case "parttimeHome":
    System.out.println("pay  " + 3465 ) ; 
    homeWorkers ++;
    break;
case "fulltimeHome":
    System.out.println("pay  " + (hours * 500) ) ; 
    homeWorkers ++;
    break;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM