本文共 5267 字,大约阅读时间需要 17 分钟。
import java.util.Scanner;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer, the input ends if it is 0: "); int pos = 0; int neg = 0; double sum = 0; int amo = 0; while(true) { int tmp = input.nextInt(); if(tmp==0) break; else { amo++; sum+=tmp; if(tmp>0) pos++; else neg++; } } double ave = sum/amo; if(amo==0) System.out.println("No numbers are entered except 0"); else { System.out.println("The number of positives is " + pos); System.out.println("The number of negatives is " + neg); System.out.println("The total is " + sum); System.out.println("The average is " + ave); } }}
import java.util.Scanner;public class book { public static void main(String[] args) { final int NUMBER_OF_QUESTIONS=10; int correctCount = 0; int count = 0; long startTime = System.currentTimeMillis(); String output=""; Scanner input = new Scanner(System.in); while(count
public class book { public static void main(String[] args) { System.out.println("千克 磅"); for(int i=1;i<=100;i++) System.out.printf("%-6d%8.1f\n",i*2-1,(2*i-1)*2.2); }}
public class book { public static void main(String[] args) { System.out.println("英里 千米"); for(int i=1;i<=10;i++) System.out.printf("%-11d%-6.3f\n",i,i*1.609); }}
public class book { public static void main(String[] args) { System.out.println("千克 磅 磅 千克"); for(int i=1;i<=100;i++) System.out.printf("%-5d%8.1f %-4d%8.2f\n",2*i-1,(2*i-1)*2.2,5*i+15,(5*i+15)/2.2); }}
public class book { public static void main(String[] args) { System.out.println("英里 千米 千米 英里"); for(int i=1;i<=10;i++) System.out.printf("%-8d%-7.3f %-8d%-6.3f\n",i,i*1.609,5*i+15,(5*i+15)/1.609); }}
public class book { public static void main(String[] args) { double ass = 10000; for(int i=0;i<10;i++) ass*=(1+0.05); double oldAss = ass; double sum = 0; for(int i=0;i<4;i++) { sum+=ass; ass*=(1+0.05); } System.out.printf("Ass after 10 years is %.2f\n",oldAss); System.out.printf("The total cost of 4 asses is %.2f\n",sum); }}
import java.util.Scanner;public class book { public static void main(String[] args) { System.out.println("Enter the number of girls: "); Scanner input = new Scanner(System.in); int num = input.nextInt(); String name = ""; double cup = 0; for(int i=0;icup) { cup=tmp; name=tname; } } System.out.println("The hottest girl is "+name); }}
import java.util.Scanner;public class book { public static void main(String[] args) { System.out.print("Enter the number of girls: "); Scanner input = new Scanner(System.in); int num = input.nextInt(); String name = ""; String name2 = ""; double cup = 0; double cup2 = 0; for(int i=0;icup) { cup2=cup; name2 = name; cup=tmp; name=tname; } else if(tmp>cup2) { cup2=tmp; name2=tname; } } System.out.println("The hottest girl is "+name); System.out.println("The second hottest girl is "+name2); }}
public class book { public static void main(String[] args) { int count=0; int base = 0; for(int i=100;i<=1000;i++) { if(i%5==0&&i%6==0) { count++; System.out.print(i+" "); } if(count%10==0&&count!=base) { System.out.print("\n"); base+=10; } } }}
public class book { public static void main(String[] args) { int count=0; int base = 0; for(int i=100;i<=1000;i++) { if(i%5==0^i%6==0) { count++; System.out.print(i+" "); } if(count%10==0&&count!=base) { System.out.print("\n"); base+=10; } } }}
public class book { public static void main(String[] args) { int n = 0; while(n*n<12000) n++; System.out.println("The n is "+n); }}
public class book { public static void main(String[] args) { int n = 0; while(n*n*n<12000) n++; System.out.println("The n is "+(n-1)); }}
转载地址:http://zuwai.baihongyu.com/