search
HomeJavajavaTutorialHow to solve Java hexadecimal conversion, input, and naming problems

Convert from decimal to binary: divide by two and take the remainder until the quotient is zero. Reverse the order of the remainder and get the value represented by binary. (The same applies to octal and hexadecimal)

Binary to octal: Binary values ​​are calculated in groups of three digits.

Binary to hexadecimal: Binary four-digit calculation value.

Converting octal and hexadecimal to binary is the inverse operation of converting binary to octal and hexadecimal.

Java input seems to be more complicated than C/C (?)

First, introduce the Scanner under the package util, create an object of the Scanner, and then the input can be performed.

The code is as follows:

import java.util.Scanner;
public class cin{
  public static void main(String[] args){
    Scanner myScanner = new Scanner(System.in);//创建Scanner的对象
    System.out.print("name:");
    String name = myScanner.next();//录入姓名
    System.out.print("age:");
    int age = myScanner.nextInt();//录入年龄
    System.out.print("score:");
    double score = myScanner.nextDouble();//录入成绩
    System.out.println();
    //依次输出姓名、年龄、成绩
    System.out.print("name: " + name);
    System.out.println();
    System.outprint("age: " + age);
    System.out.println();
    System.out.print("score: " + score);
    System.out.println();
    }
  }

The result is as follows:

How to solve Java hexadecimal conversion, input, and naming problems

A knowledge point before the correction here:

Java does not automatically wrap the output

System.out.println(); will wrap

System.out.print(); will not wrap

There are also many rules for variable naming, most of which are similar to C/C. C/C identifiers can be composed of numbers, letters and underscores and can only start with a letter underscore. In Java, you can also use one (it will change when you type it, as shown in the screenshot )

How to solve Java hexadecimal conversion, input, and naming problems

(Picture from teacher Han Shunping)

At the same time, the teacher also gave the naming convention, so I won’t list them one by one here:

How to solve Java hexadecimal conversion, input, and naming problems

Finally add some knowledge points that were not mentioned before:

There are signed numbers and unsigned numbers in C/C, but there are no unsigned numbers in Java

In the Java operator

 0001, and the operation is 0100 (this is the actual use) The operation here is 4

>> means right shift: if the number is positive, the high bit is not 0; if it is negative, the high bit Complement 1

0100, after the operation is 0001 (in actual use, the operation here is 4 >> 2, but the operation is converted into two's complement operation)

>>> ; Represents unsigned right shift (logical right shift): regardless of positive or negative, the high bit is filled with 0

after the right shift. Note: There is no

#. All of the above three are Operations based on two’s complement numbers

#

The above is the detailed content of How to solve Java hexadecimal conversion, input, and naming problems. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools