一、实验目的:
使用Java语言解决实际问题
二、实验环境
: Pc 、java编译环境
三、实验内容:
运行代码: package F;
public class First {
public static void main(String[] args)
{
String str="hello WORLD";
System.out.println(str);
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)>='A'&&str.charAt(i)<='Z') System.out.printf("%c",str.charAt(i)+32);
else if(str.charAt(i)>='a'&&str.charAt(i)<='z') System.out.printf("%c",str.charAt(i)-32);
}
}
}
运行截图:
运行代码:
package Second;
public class Second {
public static void main(String[] args)
{
String s1="helo ";
String s2="helO92344";
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s2.length();j++)
if(s1.charAt(i)==s2.charAt(j)) System.out.printf("%c\t", s2.charAt(j));
}
}
}
运行截图:
运行代码:
package TH;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TH {
public static void main(String[] args)
{
boolean b=false;
Pattern p=null;
Matcher m=null;
String str="a18@qq.com";
p=Pattern.compile("[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}");
m=p.matcher(str);
b=m.matches();
System.out.println(str+"是邮箱地址:"+b);
}
}
运行截图:
运行代码:
import com.sun.source.tree.Tree;
import java.util.*;
import java.util.Map.Entry;
public class Main {
public static void main(String[] args) {
int max=0,min=100,sum=0;
Map<String, Integer> map = new HashMap<String, Integer>();
Map<String, Integer> map2 = new TreeMap<String, Integer>();
map.put("Jack", 95);
map.put("Kevin", 85);
map.put("Thoms", 90);
map.put("Steven", 89);
map.put("Tony", 93);
map.put("July", 99);
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
for (Map.Entry<String, Integer> mapping : list) {
System.out.println(mapping.getKey() + ":" + mapping.getValue());
map2.put(mapping.getKey(),mapping.getValue());
}
Set<String> keySet = map2.keySet();
Iterator<String> iter = keySet.iterator();
while (iter.hasNext()) {
String key = iter.next();
System.out.println(key + ":" + map2.get(key));
if(map2.get(key)>max)
max=map2.get(key);
if(map2.get(key)<min)
min=map2.get(key);
sum=sum+map2.get(key);
}
System.out.println("最大值:"+max);
System.out.println("最小值:"+min);
System.out.println("平均值:"+sum/map2.size());
}
}
运行截图:
运行代码:
package Fifth;
public class ff {
public static void main(String[] args)
{
int num=-1234567;
System.out.println("二进制:"+Integer.toBinaryString(num));
System.out.println("八进制:"+Integer.toOctalString(num));
System.out.println("十六进制:"+Integer.toHexString(num));
}
}
运行截图:
6 运行代码:
package Six;
public class Six
{
public static void main(String[] args) {
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("user.dir"));
}
}
运行截图:
7 运行代码:
package SEV;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class sEV {
public static void main(String[] args)
{
BufferedReader br = null;
try {
Process p = Runtime.getRuntime().exec("net user");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (br != null)
{
try {
br.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
运行截图:
八
package four_experiment;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.text.ParseException;
public class tittle_eight {
public static void main(String[] args) throws ParseException{
SimpleDateFormat myformat=new SimpleDateFormat("yyyy年M月d日");
Date now=new Date();
System.out.println(now.toString());
System.out.println(myformat.format(now));
}
}
本文仅供参考学习,全文复制粘贴者后果自负; 强烈推荐跟动力节点学好java基础:B站链接 建议无论是工作或者是面向考研把数据结构和计算机网络学好,多学一些知识不要整天混吃等死,多出去参加计算机相关比赛例如蓝桥杯、ACM 、PTA、leetcode周赛。 推荐歌曲:晴天–JAY
|