Compare commits

...

No commits in common. 'main' and 'master' have entirely different histories.
main ... master

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Git-test.iml" filepath="$PROJECT_DIR$/Git-test.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

@ -1,2 +0,0 @@
# work2

@ -0,0 +1,27 @@
import java.util.Scanner;
public class Transform4381 {
//此代码不实现界面
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入输入数字: ");
String input = scanner.nextLine();
System.out.print("请输入从进制 (2, 8, 10, 16): ");
int fromBase = scanner.nextInt();
System.out.print("请输入到进制 (2, 8, 10, 16): ");
int toBase = scanner.nextInt();
try {
int number = Integer.parseInt(input, fromBase);
String result = Integer.toString(number, toBase);
System.out.println("转换结果: " + result);
} catch (NumberFormatException e) {
System.out.println("输入的数字在指定的进制中无效。");
}
}
}

@ -0,0 +1,15 @@
//TIP 要<b>运行</b>代码,请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Main {
public static void main(String[] args) {
//TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
// 查看 IntelliJ IDEA 建议如何修正。
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP 按 <shortcut actionId="Debug"/> 开始调试代码。我们已经设置了一个 <icon src="AllIcons.Debugger.Db_set_breakpoint"/> 断点
// 但您始终可以通过按 <shortcut actionId="ToggleLineBreakpoint"/> 添加更多断点。
System.out.println("i = " + i);
}
}
}

@ -0,0 +1,99 @@
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
public class Transform2158{
public static String convertBase(String input, int fromBase, int toBase) {
try {
int number = Integer.parseInt(input, fromBase);
return Integer.toString(number, toBase);
} catch (NumberFormatException e) {
return null;
}
}
public static boolean isValidBase(int base) {
return base == 2 || base == 8 || base == 10 || base == 16;
}
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("cli")) {
runCLI();
} else {
SwingUtilities.invokeLater(() -> new Transform2158().createAndShowGUI());
}
}
private static void runCLI() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入输入数字: ");
String input = scanner.nextLine();
System.out.print("请输入从进制 (2, 8, 10, 16): ");
int fromBase = scanner.nextInt();
System.out.print("请输入到进制 (2, 8, 10, 16): ");
int toBase = scanner.nextInt();
if (isValidBase(fromBase) && isValidBase(toBase)) {
String result = convertBase(input, fromBase, toBase);
if (result != null) {
System.out.println("转换结果: " + result);
} else {
System.out.println("输入的数字在指定的进制中无效。");
}
} else {
System.out.println("无效的进制,请输入 (2, 8, 10, 16)。");
}
scanner.close();
}
private void createAndShowGUI() {
JFrame frame = new JFrame("进制转换器");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setLayout(null);
JButton button = new JButton("开始转换");
button.setBounds(80, 70, 140, 30);
button.addActionListener(new ConvertAction());
frame.add(button);
frame.setVisible(true);
}
private static class ConvertAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String input = JOptionPane.showInputDialog("请输入输入数字:");
if (input == null) return;
String fromBaseStr = JOptionPane.showInputDialog("请输入从进制 (2, 8, 10, 16):");
if (fromBaseStr == null) return;
String toBaseStr = JOptionPane.showInputDialog("请输入到进制 (2, 8, 10, 16):");
if (toBaseStr == null) return;
try {
int fromBase = Integer.parseInt(fromBaseStr);
int toBase = Integer.parseInt(toBaseStr);
if (isValidBase(fromBase) && isValidBase(toBase)) {
String result = convertBase(input, fromBase, toBase);
if (result != null) {
JOptionPane.showMessageDialog(null, "转换结果: " + result);
} else {
JOptionPane.showMessageDialog(null, "输入的数字在指定的进制中无效。");
}
} else {
JOptionPane.showMessageDialog(null, "无效的进制,请输入 (2, 8, 10, 16)。");
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "输入的数字在指定的进制中无效。");
}
}
}
}
Loading…
Cancel
Save