用JAVA语言编写程序
答案:3 悬赏:40 手机版
解决时间 2021-03-15 22:41
- 提问者网友:活着好累
- 2021-03-15 02:58
用JAVA语言编写程序
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-03-15 04:09
public class Test {
public static void main(String args[])
{
int n=100,m=200;
int sum=0,tem=0;
System.out.println("100到200之间所以3的倍数为:");
for(int i=n;i<=m;i++)
{
if(i%3==0)
{
System.out.print(i+" ");
sum+=i;
tem++;
}
if(tem%10==0)
System.out.println();
}
System.out.println();
System.out.print("所有3的倍数之和为:"+sum);
}
}
public static void main(String args[])
{
int n=100,m=200;
int sum=0,tem=0;
System.out.println("100到200之间所以3的倍数为:");
for(int i=n;i<=m;i++)
{
if(i%3==0)
{
System.out.print(i+" ");
sum+=i;
tem++;
}
if(tem%10==0)
System.out.println();
}
System.out.println();
System.out.print("所有3的倍数之和为:"+sum);
}
}
全部回答
- 1楼网友:忘川信使
- 2021-03-15 05:34
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class SaleTickets { private static int getChoice() {BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));int result;try {result = Integer.parseInt(reader.readLine());}catch(NumberFormatException e) {result = -1;}catch(IOException ioe) {return -1;}return result; }public static void main(String[] args) {int noSmoking = 5; //指示当前应该分配的无烟区int somking = 0;//指示当前应该分配的吸烟区int choice;System.out.println("1 Please type 1 for \"smoking\":\n" +"2 Please type 2 for \"no somking\":\n" +"0 Exit the system");choice = getChoice();while(choice != 0) { //分配座位 switch(choice) {case 1: //吸烟区if(somking < 5) {System.out.println("Congratulations, yout got a seat in somking area " + "your seatNo is " + (somking++ + 1));}//吸烟区已经没有座位了else {System.out.println("There is no seat is smoking area, " + "would you like a seat in no smoking area? type 1 for yes and 0 for no: "); switch(getChoice()) {case 1:if(noSmoking < 10) {System.out.println("Congratulations, you got a seat in no smoking area" + " your seatNo is " + (noSmoking++ + 1));}else {System.out.println("wait for next flight!");}break; case '0':default: break; }}break; case 2://无烟区if(noSmoking < 10) {System.out.println("Congratulations, you got a seat in no smoking area" + " your seatNo is " + (noSmoking++ +1));}else {System.out.println("wait for next flight!");}break;default: System.out.println("Invalid choice!"); }System.out.println("1 Please type 1 for \"smoking\":\n" + "2 Please type 2 for \"no somking\":\n" + "0 Exit the system"); choice = getChoice();}System.out.println("Good bye!"); }}没有按你的提示来实现。
- 2楼网友:洎扰庸人
- 2021-03-15 04:15
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class SaleTickets { private static int getChoice() {BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));int result;try {result = Integer.parseInt(reader.readLine());}catch(NumberFormatException e) {result = -1;}catch(IOException ioe) {return -1;}return result; }public static void main(String[] args) {int noSmoking = 5; //指示当前应该分配的无烟区int somking = 0;//指示当前应该分配的吸烟区int choice;System.out.println("1 Please type 1 for \"smoking\":\n" +"2 Please type 2 for \"no somking\":\n" +"0 Exit the system");choice = getChoice();while(choice != 0) { //分配座位 switch(choice) {case 1: //吸烟区if(somking < 5) {System.out.println("Congratulations, yout got a seat in somking area " + "your seatNo is " + (somking++ + 1));}//吸烟区已经没有座位了else {System.out.println("There is no seat is smoking area, " + "would you like a seat in no smoking area? type 1 for yes and 0 for no: "); switch(getChoice()) {case 1:if(noSmoking < 10) {System.out.println("Congratulations, you got a seat in no smoking area" + " your seatNo is " + (noSmoking++ + 1));}else {System.out.println("wait for next flight!");}break; case '0':default: break; }}break; case 2://无烟区if(noSmoking < 10) {System.out.println("Congratulations, you got a seat in no smoking area" + " your seatNo is " + (noSmoking++ +1));}else {System.out.println("wait for next flight!");}break;default: System.out.println("Invalid choice!"); }System.out.println("1 Please type 1 for \"smoking\":\n" + "2 Please type 2 for \"no somking\":\n" + "0 Exit the system"); choice = getChoice();}System.out.println("Good bye!"); }}没有按你的提示来实现。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯