Lab Purpose
1. Understand Java input and output programming and operations.
2. Learn about the input and output on the Java application character interface.
Lab content
Write a Java application program.
1) read a three-digit integer from the console
2) output it in reverse order (for example, if 123 is input, the output result is 321)
Description: an int type is read from the console. The entire division and remainder are used to output the data in reverse order.
Note
1. Java is case sensitive and must be noted. For example, in system, in bytes, S, I, and in nextline.
2. The program is composed of a series of statements. ";" must be added at the end of the statement, and the symbols in the Java program must be entered in English; otherwise, a syntax error occurs.
3. in Java, each class is in a separate file, and the class name must be the same as the file name. The class that can be run must contain the public static void main (string [] ARGs) and can only be compiled without the main method.
4. Pay attention to the friendliness of the program interface. For example, you should be prompted before asking the user to input an integer from the interface. Repeated scan = new partition (system. In );
System. Out. println ("Please input an integer :");
Scan. readlineint ();
5. The Division operator "/" is an integer operation that directly discards the part after the decimal point.
-----------------------------------------------------------------------------
Below is my code
-----------------------------------------------------------------------------
import java.util.Scanner;public class shiyan2 {public static void main(String arg[]){int a,s;Scanner scan=new Scanner(System.in);System.out.println("please input an integer(3):");a=scan.nextInt();s=a%10*100+(a%100-a%10)+a/100;System.out.println(s);}}
Now let's think about it. The experiment requires that we use an int integer because we haven't learned the string, so we have limited three digits.
If a string is used, you can output a string in reverse order, not limited to numbers or length. it is also very simple, that is, the output string in reverse order. I will not write it here. When beginners learn the string, they can think about it and practice it.