//Hello World!
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
//你好
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
System.out.println("Hello "+name);
sc.close();
}
}
//Say Hello to Integers
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("Hello, "+a+" and "+b+"!");
sc.close();
}
}
//基本格式输入输出
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char c = scanner.next().charAt(0);
int i = scanner.nextInt();
double d = scanner.nextDouble();
System.out.println(c);
System.out.println(i);
System.out.printf("%.6f", d);
}
}
//能够被3整除元素的奇数和偶数的个数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int oddCount = 0, evenCount = 0;
for (int i = 1; i <= n; i++) {
if (i % 2 == 1 && i % 3 == 0) {
oddCount++;
} else if (i % 2 == 0 && i % 3 == 0) {
evenCount++;
}
}
System.out.printf("%d,%d\n", oddCount, evenCount);
}
}
//求一组数组中的平均数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = 10;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += in.nextInt();
}
double avg = (double) sum / n;
System.out.printf("%.2f", avg);
in.close(); //关闭输入流
}
}
//高速公路超速处罚
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int speed = in.nextInt();
int limit = in.nextInt();
double exceed = (double)(speed - limit) / limit * 100;
if (exceed < 10) {
System.out.println("OK");
} else if (exceed < 50) {
System.out.printf("Exceed %.0f%%. Ticket 200", exceed);
} else {
System.out.printf("Exceed %.0f%%. License Revoked", exceed);
}
in.close();
}
}
//设计一个矩形类Rectangle
import java.util.Scanner;
class Rectangle{
private double width = 1.0;
private double height = 1.0;
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
public double getArea() {
return this.height * this.width;
}
public double getPerimeter() {
return 2 * (this.height + this.width);
}
}
// 根据派生类写出基类
public People(){
}
public People(String id, String name){
this.id = id;
this.name = name;
}
public void setId(String id){
this.id = id;
}
public void setName(String name){
this.name = name;
}
public String getId(){
return id;
}
public String getName(){
return name;
}
public void say() {
System.out.println("I'm a person! My name is " + this.name + ".");
}
//设计Worker类及其子类
class Worker {
String name;
double hourPay;
public Worker() {
}
public Worker(String name, double hourPay) {
this.name = name;
this.hourPay = hourPay;
}
public double getHourPay() {
return hourPay;
}
public void setHourPay(int hourPay) {
this.hourPay = hourPay;
}
public void pay(double workHour) {
System.out.println("Not Implemented");
}
}
class HourlyWorker extends Worker {
public HourlyWorker(String name, double hourPay) {
this.name = name;
this.hourPay = hourPay;
}
public void pay(double workHour) {
if (workHour <= 40) {
System.out.println((workHour * hourPay));
} else
System.out.println((((workHour - 40) * 2) + 40) * hourPay);
}
public void setRate(double hourPay) {
this.hourPay = hourPay;
}
}
class SalariedWorker extends Worker {
public SalariedWorker(String name, double hourPay) {
this.name = name;
this.hourPay = hourPay;
}
public void pay() {
System.out.println((40 * hourPay));
}
public void pay(double workHour) {
System.out.println((40 * hourPay));
}
}
//卡车载重
interface ComputeWeight {
public abstract double computeWeight();
}
class Television implements ComputeWeight {
public double computeWeight() {
return 16.6;
}
}
class AirConditioner implements ComputeWeight {
public double computeWeight() {
return 40.0;
}
}
class WashMachine implements ComputeWeight {
public double computeWeight() {
return 60.0;
}
}
class Truck{
private ComputeWeight[] goods;
public Truck(ComputeWeight[] goods){
this.goods =goods;
}
public double getTotalWeight(){
double result = 0;
for(int i = 0 ; i < goods.length;i++){
result += goods[i].computeWeight();
}
return result;
}
}
//成绩分级管理
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
scanner.close();
String grade;
if (score < 60) {
grade = "E";
} else if (score < 70) {
grade = "D";
} else if (score < 80) {
grade = "C";
} else if (score < 90) {
grade = "B";
} else {
grade = "A";
}
System.out.println(grade);
}
}
//求圆面积自定义异常类
class Circle{
double r;
public Circle(double r){
this.r = r;
}
public double area() throws CircleException{
if(r<=0){
throw new CircleException(this.r);
}
return (this.r * this.r * 3.14);
}
}
class CircleException extends Exception{
double r;
public CircleException(){
}
public CircleException(double r){
this.r = r;
}
public void print(){
System.out.println("圆半径为"+this.r+"不合理");
}
}
//成绩录入时的及格与不及格人数统计
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int score;
int unPass = 0;
int Pass = 0;
for(int i = 0 ; i < n;i++){
score = sc.nextInt();
if(score<0||score>100){
try{
throw new ScoreExcrption(score);
}catch(ScoreExcrption e){
System.out.println(e.toString());
i--;
}
}else if(score <60) unPass++;
else Pass++;
}
sc.close();
System.out.println(Pass);
System.out.println(unPass);
}
}
class ScoreExcrption extends Exception{
int score;
public ScoreExcrption(){
}
public ScoreExcrption(int score){
this.score = score;
}
public String toString(){
return this.score+"invalid!";
}
}
//年-月-日
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String idNums[] = new String[n];
for (int i = 0; i < n; i++) {
idNums[i] = sc.next();
}
while (true) {
String xuanze = sc.next();
if (xuanze.equals("sort1"))
sort1(idNums);
else if (xuanze.equals("sort2"))
sort2(idNums);
else {
System.out.println("exit");
break;
}
}
sc.close();
}
// 年-月-日 升序
public static void sort1(String a[]){
int len = a.length;
String b[] = new String[len];
for(int i = 0 ; i < len ; i++){
b[i] = a[i].substring(6, 14);
}
Arrays.sort(b);
for(int i = 0 ; i < len ; i++){
System.out.println(b[i].substring(0,4)+"-"+b[i].substring(4,6)+"-"+b[i].substring(6, 8));
}
}
// 全部身份证号 年-月-日 升序
public static void sort2(String a[]){
int len = a.length;
String b[] = new String[len];
for(int i = 0 ; i < len ; i++){
b[i] = a[i].substring(6, 14);
}
Arrays.sort(b);
Arrays.sort(a);
for(int i = 0 ; i < len ;i ++){
for( int j = 0 ; j < len; j++){
if(a[j].contains(b[i])){
System.out.println(a[j]);
}
}
}
}
}
//年-月
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
String idNums = sc.next();
if(idNums.length()!=18){
System.out.println("Invalid data,input again!");
}else{
System.out.println(idNums.substring(6, 10)+","+idNums.substring(10,12));
break;
}
}
}
}
//重复数据问题
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String nums = sc.nextLine();
sc.close();
String numsAfter[] = nums.split(" ");
boolean result = false;
for(int i = 0 ; i < numsAfter.length; i ++){
for(int j = 0 ; j < numsAfter.length ; j++){
// 这里一定要注意 一定不能自己和自己比较,所以加条件 i != j
if(numsAfter[i].equals(numsAfter[j])&& i != j ){
result = true;
}
}
}
if(result == true){
System.out.println("yes");
}else System.out.println("no");
}
}
//统计指定字母开头单词的数量
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
sc.close();
String words[] = input.split(" ");
int result = 0;
for(int i = 1; i < words.length;i++){
if(words[0].equals(words[i].substring(0, 1))){
result++;
}
}
System.out.print(result);
}
}