Skip to content

Commit

Permalink
日常练习
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunbeam-5 committed Jun 3, 2022
1 parent 416a3c5 commit 4c03266
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 0 deletions.
Binary file not shown.
Binary file added 20220531/out/production/20220531/StringUtilMax.class
Binary file not shown.
Binary file added 20220531/out/production/20220531/StringUtilMin.class
Binary file not shown.
Binary file added 20220531/out/production/20220531/TestChange.class
Binary file not shown.
57 changes: 57 additions & 0 deletions 20220531/src/InitialsTransformation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//package Main;

/**
*
* @Explain(说明):字符串首字母大小写转换工具类
* @time(时间):2019/04/17
* @role(谁):杨木发
* @modify(修改)
* @time:
* @role:
*/


public class InitialsTransformation {
public static void main(String[] args) {
System.out.println(StringUtilMax.initcap("yangmufa")) ;
System.out.println(StringUtilMin.initcap1("YANGMUFA")) ;
}
}




class StringUtilMax{
public static String initcap(String str){
//如果字符串str为null和""则返回原数据
if (str==null||"".equals(str)){
return str ;
}

if(str.length()==1){
//如果字符串str的长度为1,则调用专门把字符串转换为大写的string方法tuUpperCase()
return str.toUpperCase() ;
}
//用字符串截取方法subString()截取第一个字符并调用toUpperCase()方法把它转换为大写字母
//再与从str第二个下标截取的字符串拼接
return str.substring(0,1).toUpperCase()+str.substring(1) ;
}
}


class StringUtilMin{
public static String initcap1(String str){
//如果字符串str为null和""则返回原数据
if (str==null||"".equals(str)){
return str ;
}

if(str.length()==1){
//如果字符串str的长度为1,则调用专门把字符串转换为小写的string方法tuUpperCase()
return str.toLowerCase() ;
}
//用字符串截取方法subString()截取第一个字符并调用toUpperCase()方法把它转换为小写字母
//再与从str第二个下标截取的字符串拼接
return str.substring(0,1).toLowerCase()+str.substring(1) ;
}
}
32 changes: 32 additions & 0 deletions 20220531/src/TestChange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
大小写转换
**/
import java.util.Scanner;

class TestChange
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
System.out.println(changeStr(str1));
}

public static String changeStr(String str){

char[] c = str.toCharArray(); //先将字符串转换成字符数组
int value = 'a'-'A'; //计算大小写间差值:32

//循环遍历字符数组
for(int i = 0; i < c.length; i++){
if('a'<=c[i] && c[i] <='z'){
c[i] = (char)(c[i]-value); //小写变大写
}else if('A'<=c[i] && c[i] <='Z'){
c[i] = (char)(c[i]+value); //大写变小写
}
}

String laststr = new String(c); //再将字符数组转换成字符串
return laststr;
}
}
3 changes: 3 additions & 0 deletions 20220602/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 20220602/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 20220602/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 20220602/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions 20220602/20220602.iml
Original file line number Diff line number Diff line change
@@ -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>
Binary file not shown.
Binary file added 20220602/out/production/20220602/求阶乘和.class
Binary file not shown.
5 changes: 5 additions & 0 deletions 20220602/src/找出出现一次的数字.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class 找出出现一次的数字 {
public static void main(String[] args) {

}
}
18 changes: 18 additions & 0 deletions 20220602/src/求和的重载.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;

public class 求和的重载 {
public static void main(String[] args) {
int a = 10, b = 20;
double x = 6.4, y = 3.2, z = 5.2;
int sum1 = add(a,b);
double sum2 = add(x,y,z);
System.out.println(sum1);
System.out.println(sum2);
}
public static int add(int a, int b){
return a+b;
}
public static double add(double a, double b, double c){
return a+b+c;
}
}
19 changes: 19 additions & 0 deletions 20220602/src/求阶乘和.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Scanner;

public class 求阶乘和 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ret = func(n);
System.out.println(ret);
}

public static int func(int n){
int sum = 0, a = 1;
for (int i = 1; i <= n; i++) {
a *= i;
sum += a;
}
return sum;
}
}

0 comments on commit 4c03266

Please sign in to comment.