import java.util.Scanner;
class Person
{
private String name;
private int age;
private boolean gender;
private int id;
public String getname(){
return name;
}
public void setname(String name){
this.name=name;
}
public int getage(){
return age;
}
public void setage(int age){
this.age=age;
}
public boolean getgender(){
return gender;
}
public void setgender(boolean gender){
this.gender=gender;
}
public int getid(){
return id;
}
public void setid(int id){
this.id=id;
}
public Person()
{
System.out.println("This is constructor");
//System.out.println("Person [name="+name+", age="+age+", gender="+gender+", id="+id+"]");
System.out.println(name+","+age+","+gender+","+id);
//System.out.println("Person [name=null, age=0, gender=false, id=0]");
}
public Person(String name ,int age, boolean gender)
{
this.name=name;
this.age=age;
this.gender=gender;
}
public String toString()
{
return "Person [name="+name+", age="+age+", gender="+gender+", id="+id+"]";
}
}
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Person[] p=new Person[n];
for(int i=0;i<n;i++){
String a=sc.next();
int b=sc.nextInt();
boolean c=sc.nextBoolean();
p[i]=new Person(a,b,c);
}
for(int i=n-1;i>=0;i--)
{
System.out.println(p[i].toString());
}
Person pp=new Person();
System.out.println(pp.toString());
}
}
//----------------------------------------------------------------------------------------------------------------------------
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Rectangle[] rectangle=new Rectangle[2];
rectangle[0]=new Rectangle(in.nextInt(),in.nextInt());
rectangle[1]=new Rectangle(in.nextInt(),in.nextInt());
Circle[] circles=new Circle[2];
circles[0]=new Circle(in.nextInt());
circles[1]=new Circle(in.nextInt());
System.out.println(rectangle[0].getPerimeter()+rectangle[1].getPerimeter()+
circles[0].getPerimeter()+circles[1].getPerimeter());
System.out.println(rectangle[0].getArea()+rectangle[1].getArea()+
circles[0].getArea()+circles[1].getArea());
System.out.println(Arrays.deepToString(rectangle));
System.out.println(Arrays.deepToString(circles));
}
}
class Rectangle{
private int width;
private int length;
public Rectangle (int width,int length){
this.width=width;
this.length=length;
}
public int getPerimeter(){
return (width+length)*2;
}
public int getArea(){
return width*length;
}
public String toString(){
return "Rectangle [" + "width=" + width + ", length=" + length + ']';
}
}
class Circle{
private int radius;
private double s;
public Circle(int radius){
this.radius=radius;
}
public int getPerimeter() {
s = (Math.PI * 2 * radius);
return (int)s;
}
public int getArea(){
s = (Math.PI * radius * radius);
return (int) s;
}
public String toString() {
return "Circle [" + "radius=" + radius + ']';
}
}
//-------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String name=sc.next();
int age=sc.nextInt();
String sex=sc.next();
Student s=new Student(name,sex,age);
System.out.println(s.toString());
}
}
class Student
{
private String name;
private String sex;
private int age;
public Student(String name ,String sex,int age){
this.name =name;
this.sex=sex;
this.age=age;
}
public String toString(){
return "Student [name='" +name+ "', sex='" +sex+ "', age=" +age+ "]";
}
}
//----------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
int e=sc.nextInt();
System.out.println(a);
System.out.println(b+c);
System.out.println(d*e);
}
}
//---------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
class Goods
{
private String name;
private double price;
public Goods(String name,double price)
{
this.name=name;
this.price=price;
}
public double getPrice(){
return price;
}
public String toString(){
return name+","+price;
}
}
class Main{
public static void main(String args[]){
Goods ga[] =new Goods[5];
Scanner sc = new Scanner(System.in);
for(int i =0;i<5;i++){
ga[i]= new Goods(sc.next(),sc.nextDouble());
}
double shouldPay = 0;
for(Goods g:ga){
shouldPay += g.getPrice();
System.out.println(g.toString());
}
System.out.println("should pay:"+shouldPay);
}
}
//--------------------------------------------------------------------------------------------------------
import java.util.Scanner;
class Student
{
private String name;
private String gender;
private int score;
private boolean award;
public Student(String name,String gender,int score,boolean award)
{
this.name=name;
this.gender=gender;
this.score=score;
this.award=award;
}
//public
public String toString(){
return "Student "+"[name="+name+", gender="+gender+", score="+score+", award="+award+"]";
}
}
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String name=sc.next();
String gender=sc.next();
int score=sc.nextInt();
boolean award=sc.nextBoolean();
Student st=new Student(name,gender,score,award);
System.out.println(st.toString());
}
}
//-----------------------------------------------------------------------------------------------
import java.util.Scanner;
class Main{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
Teacher[] t = new Teacher[2];
int a=0;
int b=0;
for(int i=0;i<2;i++){
int no=sc.nextInt();
String name = sc.next();
int age = sc.nextInt();
String se=sc.next();
t[i]=new Teacher(no,name,age,se);
if(i==0) a=no;
else b=no;
}
for(int i=0;i<2;i++)
{
System.out.println(t[i].toString());
}
if(a==b) System.out.printf("true");
else System.out.printf("false");
}
}
class Teacher{
private int no;
private String name;
private int age;
private String se;
public Teacher(int no,String name ,int age,String se)
{
this.no=no;
this.name=name;
this.age=age;
this.se=se;
}
public String toString(){
return "no: " +no+ ", name:" +name+ ", age: " +age+ ", seminary: "+se;
}
}
//---------------------------------------------------------------------------------------------------
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double sum1 = 0;
double sum2 = 0;
String C1 = sc.next();
double C2 = sc.nextDouble();
sum1 += C2;
int C3 = sc.nextInt();
sum1 += C3;
String G = sc.next();
String X1 = sc.next();
int X2 = sc.nextInt();
sum1 += X2;
String S1 = sc.next();
int S2 = sc.nextInt();
sum1 += S2;
String SS1 = sc.next();
int SS2 = sc.nextInt();
sum1 += SS2;
// 读取第二部分输入
String c1 = sc.next();
double c2 = sc.nextDouble();
sum2 += c2;
int c3 = sc.nextInt();
sum2 += c3;
String g = sc.next();
String x1 = sc.next();
int x2 = sc.nextInt();
sum2 += x2;
String s1 = sc.next();
int s2 = sc.nextInt();
sum2 += s2;
String ss1 = sc.next();
int ss2 = sc.nextInt();
sum2 += ss2;
// 检查总和是否相等
if (sum1 == sum2) {
System.out.println("true");
} else {
System.out.println("false");
}
// 输出计算机1的信息
System.out.println("Computer1:");
System.out.println("CPU:");
System.out.printf("Model: %s\n", C1);
System.out.printf("Frequency: %.1f\n",C2);
System.out.printf("Number of Cores: %d\n",C3);
System.out.printf("Mainboard:\n");
System.out.printf("Model: %s\n", G);
System.out.printf("Memory:\n");
System.out.printf("Model: %s\n", X1);
System.out.printf("Size: %d\n",X2);
System.out.printf("Screen:\n");
System.out.printf("Model: %s\n", S1);
System.out.printf("Size: %s\n", S2);
System.out.printf("Harddisk:\n");
System.out.printf("Model: %s\n", SS1);
System.out.printf("Size: %d\n", SS2);
System.out.println("Computer2:");
System.out.println("CPU:");
System.out.printf("Model: %s\n", c1);
System.out.printf("Frequency: %.1f\n",c2);
System.out.printf("Number of Cores: %d\n",c3);
System.out.printf("Mainboard:\n");
System.out.printf("Model: %s\n", g);
System.out.printf("Memory:\n");
System.out.printf("Model: %s\n", x1);
System.out.printf("Size: %d\n",x2);
System.out.printf("Screen:\n");
System.out.printf("Model: %s\n", s1);
System.out.printf("Size: %s\n", s2);
System.out.printf("Harddisk:\n");
System.out.printf("Model: %s\n", ss1);
System.out.printf("Size: %d\n", ss2);
}
}
//-----------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//调用无参构造方法,并通过setter方法进行设值
String sid1 = sc.next();
String name1 = sc.next();
int age1 = sc.nextInt();
String major1 = sc.next();
Student student1 = new Student();
student1.setSid(sid1);
student1.setName(name1);
student1.setAge(age1);
student1.setMajor(major1);
//调用有参构造方法
String sid2 = sc.next();
String name2 = sc.next();
int age2 = sc.nextInt();
String major2 = sc.next();
Student student2 = new Student(sid2, name2, age2, major2);
//对学生student1和学生student2进行输出
student1.print();
student2.print();
}
}
class Student{
private String sid ;
private String name ;
private int age ;
private String major ;
public Student(String sid,String name,int age,String major)
{
this.sid=sid;
this.name=name;
this.age=age;
this.major=major;
}
public Student()
{
this.sid=sid;
this.name=name;
this.age=age;
this.major=major;
}
public void setSid(String sid){
this.sid=sid;
}
public void setName(String name){
this.name=name;
}
public void setAge(int age)
{
this.age=age;
}
public void setMajor(String major)
{
this.major=major;
}
public void print() {
System.out.println("学号:" + sid + ",姓名:" + name + ",年龄:" + age + ",专业:" + major);
}
}
标签:JAVA,String,int,age,System,public,name
From: https://www.cnblogs.com/Minyou03/p/18577468