失效链接处理 |
Java结业实验复习资料题目大全 PDF 下载
本站整理下载:
相关截图:
主要内容:
Problem 01
Given a positive integer num, return its length. You may assume that num
is int type.
Code
package com.exp;
import java.util.Scanner;
public class IntNumLength {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个整数: ");
int param = sc.nextInt();
sc.close();
int len = String.valueOf(param).length();
System.out.print(param + "的长度为 " + len);
} }
Operation results
请输入一个整数: 44
44 的长度为 2
请输入一个整数: 357
357 的长度为 3
请输入一个整数: 3424243
3424243 的长度为 7
Problem 02
Given a positive integer num, output each digit of it from left to right. You
may assume that num is int type.
Code
package com.exp;
import java.util.Scanner;
public class IntSingleDigit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个整数: ");
int param = sc.nextInt();
sc.close();
System.out.print("输入整数的单个数字为: ");
String str = String.valueOf(param);
for (int i = 0; i < str.length(); ++i) {
System.out.print(str.charAt(i) + " ");
} } }
|