Java Basic syntax

Source: Internet
Author: User
Tags stub

The first week of contact with Java Basic Grammar, the class to listen to headaches, or half understand, after-school talk about what are forgotten.

This is the weekend homework given by the teacher:

1. Enter the length and width to calculate the rectangular area and perimeter. (Calculated with precision type)
2. Enter a student's score of three subjects and calculate the average score.
3, enter the int type market price, purchase prices, calculate the difference, the difference is displayed as single-precision floating-point type.
4, 42 pages second, calculate the problem of the mortgage.
5, input A student achievement, the academic achievement >=90 cent's classmate uses a to indicate, 60-89 minutes between the use B to indicate, 60 points below uses C to indicate.
6, Title: Input three integer x, y, Z, please put these three numbers from small to large output.
Program Analysis: We try to put the smallest number on the X, first compare x with Y, if x>y the value of x and Y, and then compare X with Z, if x>z the value of X and Z, this will make x the smallest.

7. Enter a three-digit number to determine the number of daffodils. For example 153 = 1*1*1 + 5*5*5 + 3*3*3
8, Title: A company using public telephones to transmit data, the data is a four-bit integer, in the transmission process is encrypted, the encryption rules are as follows: Each digit is added 5, and then divided by the remainder of 10 instead of the number, and then the first and fourth exchange, the second and third exchange.

The front four questions oneself completes independently, does not know has the question, is not very neat, will look.

1. Enter the length and width to calculate the rectangular area and perimeter. (Calculated with precision type)

Package zuoye28;
Import Java.util.Scanner;

public class Zuoye1 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub

Scanner s1=new Scanner (system.in);
System.out.println ("Please enter Long");
int A=s1.nextint ();

Scanner s2=new Scanner (system.in);
System.out.println ("Please enter the width");
int B=s2.nextint ();
Double ji=a*b;
Double zhou= (a+b) * *;
System.out.println (JI);
System.out.println (Zhou);
}

}

2.2. Enter a student's score of three subjects and calculate the average score.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye2 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);
System.out.println ("Language score:");
int Yw=s1.nextint ();

Scanner s2=new Scanner (system.in);
System.out.println ("Math score:");
int Sx=s2.nextint ();

Scanner s3=new Scanner (system.in);
System.out.println ("English score:");
int Yy=s3.nextint ();
Double ping= (YW+SX+YY)/3;
System.out.println (ping);

}

}

3.3, enter the int type market price, purchase prices, calculate the difference, the difference is displayed as single-precision floating-point type.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye3 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Market Price:");
int Shi=s1.nextint ();

Scanner s2=new Scanner (system.in);
System.out.println ("wholesale price:");
int Gou=s2.nextint ();

float Cha=shi-gou;
System.out.println (CHA);
}

}

4.4, 42 pages Second, calculate the problem of the mortgage.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye4 {

/**
* @param args
*/
public static void Main (string[] args) {

Scanner s1=new Scanner (system.in);
System.out.println ("principal");
Double p=s1.nextdouble ();

Scanner s2=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("interest rate");
Double rate=s2.nextdouble ();

Scanner s3=new Scanner (system.in);
System.out.println ("Years");
int Y=s3.nextint ();

int n=y*12;
Double r=rate/(12*100);
Double Z=math.pow (1+r,-n);
Double yue=p* (r/(1-z));
System.out.println ("Monthly repayment Amount:" +yue);
}

}

5, input A student achievement, the academic achievement >=90 cent's classmate uses a to indicate, 60-89 minutes between the use B to indicate, 60 points below uses C to indicate.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye5 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub

Scanner s1=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Student performance:");
int Chengji=s1.nextint ();

System.out.print ("Your rank:");
System.out.print (chengji<60? ") C ":");
System.out.print ((59<chengji&chengji<90)? " B ":");
System.out.print (chengji>=90? ") A ":");
}

}

The first five questions are all self-made, of course not all are knocked out copy some. The fourth question was also taught by one of the classmates.

Package zuoye28;

Import Java.util.Scanner;

public class Zuoye6 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);
System.out.println ("Integer 1");
int X=s1.nextint ();

Scanner s2=new Scanner (system.in);
System.out.println ("Integer 2");
int Y=s2.nextint ();

Scanner s3=new Scanner (system.in);
System.out.println ("Integer 3");
int Z=s3.nextint ();


System.out.println (x>y? ( X=Y>Z?Z:Y):(x>z?z:x));
System.out.println (x>y|y<z? ( X>Z|Z<Y?Z:Y):(y>x|x<z?x:z));
System.out.println (z>x? ( Z>Y?Z:Y):(x>y?x:y));
}

}

6, Title: Input three integer x, y, Z, please put these three numbers from small to large output.
Program Analysis: We try to put the smallest number on the X, first compare x with Y, if x>y the value of x and Y, and then compare X with Z, if x>z the value of X and Z, this will make x the smallest.

Because there is no teaching cycle, only teach the three mesh operator, the teacher said do not do. I did it too, but the minimum output is correct, and the output on the back is wrong.

Package zuoye28;

Import Java.util.Scanner;

public class Zuoye6 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);
System.out.println ("Integer 1");
int X=s1.nextint ();

Scanner s2=new Scanner (system.in);
System.out.println ("Integer 2");
int Y=s2.nextint ();

Scanner s3=new Scanner (system.in);
System.out.println ("Integer 3");
int Z=s3.nextint ();


System.out.println (x>y? ( X=Y>Z?Z:Y):(x>z?z:x));
System.out.println (x>y|y<z? ( X>Z|Z<Y?Z:Y):(y>x|x<z?x:z));
System.out.println (z>x? ( Z>Y?Z:Y):(x>y?x:y));
}

}

7. Enter a three-digit number to determine the number of daffodils. For example 153 = 1*1*1 + 5*5*5 + 3*3*3

Tangled up for a long time what the meaning of the symbol, but fortunately at the end of the figure, this is also the Daniel taught.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye7 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);

int A=s1.nextint ();
int d= (a)%10;
int b= (A/10)%10;
int c= (a/100)%10;
System.out.println (a==c*c*c+b*b*b+d*d*d? " Yes: "no"));




}
}


8, Title: A company using public telephones to transmit data, the data is a four-bit integer, in the transmission process is encrypted, the encryption rules are as follows: Each digit is added 5, and then divided by the remainder of 10 instead of the number, and then the first and fourth exchange, the second and third exchange.

This is a reference to the seventh problem, and worked for several hours. It's kind of a self-made.

Package zuoye28;
Import Java.util.Scanner;
public class Zuoye8 {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner s1=new Scanner (system.in);
System.out.println ("integer");
int Z=s1.nextint ();
int z4=z%10;
int z3= (Z/10)%10;
int z2= (z/100)%10;
int z1= (z/1000)%10;
int e= (z1+5)%10;
int f= (z2+5)%10;
int g= (z3+5)%10;
int h= (z4+5)%10;
SYSTEM.OUT.PRINTLN ("The result is" +h+g+f+e);
}

}

All over the cuffs. I am grateful to the great God who feels that something is wrong.

Java Basic syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.