用Java编写一个程序

用java编写一个程序~

public class Test {
public static void main(String[] args) {
while (true) {
System.out.print("请输入姓名:");
Scanner input = new Scanner(System.in);
String name = input.next();
System.out.println("请输入的姓名是:"+name);
}
}
}

public class Du1 {

public static void main(String[] args) {

int year = 2011;

if((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 100 == 0) ){
System.out.println("是闰年");
}else{
System.out.println("It is ");
}

}
}

public Map<String,Integer> getCharacterNum(String str)
{
//封装一个Map,key为String类型,value为字母数,其中key为UpperChar的value存大写字母 数
// key 为NumberChar的value存放数字
//key为LowerChar的value存放小写字母数,key为OtherChar的value存放非英文字母数
Map<String,Integer> map = new HashMap<String,Integer>();
int upperValue = 0;
int lowerValue = 0;
int otherValue = 0;
int numberValue = 0;
for (int i = 0 ; i < str.length(); i++)
{
if (str.charAt[i] > 'a' && str.charAt[i] < 'z')
{
lowerValue++;
}
else if (str.charAt[i] > 'A' && str.charAt[i] < 'Z')
{
upperValue++;
}
else if (str.charAt[i] > '0' && str.charAt[i] < '9')
{
numberValue ++;
}
else
{
otherValue++;
}
}
map.put("UpperChar",upperValue);
map.put("LowerChar",lowerValue);
map.put("OtherChar",otherValue);
map.put("NumberChar",numberValue);
return map;
}

public static void main(Stirng[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String str = sc.nextLine();
类名 objClass = new 类名(); //这里的类名为当前创建的类名
Map<String,Integer> dataMap = objClass.getCharacterNum(str);
//大写字母的数量

int upChar = dataMap.get("UpperChar");
//小写字母数量
int lowerChar = dataMap.get("LowerChar");

//数字数量
int numChar = dataMap.get("NumberChar");
//其他字母数量
int otherChar = dataMap.get("OtherChar");
}

public static void test_7(){
System.out.println("请输入一个字符串:");

String str = in.nextLine();
char[] arr = str.toCharArray();
int a=0;
int b=0;
int c=0;
int d=0;
for(int i=0;i<arr.length;i++){
if(arr[i]>='A' && arr[i]<='Z')
a++;
else if(arr[i]>='a' && arr[i]<='z')
b++
else if(arr[i]>='0' && arr[i]<='9')
c++;
else
d++;
}
System.out.print("大写字母个数为:"+a+"\n小写字母个数为:"+b+"\n数字的个数为:"+c+"\n其他字符个数为:"+d);
}

import java.util.Scanner;

public class Test4_9 {
public static void main(String[] args) {
String str = "";
System.out.println("请输入字符串:");
Scanner console = new Scanner(System.in);
str = console.nextLine();
byte[] arr = str.getBytes();
long dx=0,xx=0,zs=0,qt=0;
for (int i = 0; i < arr.length; i++) {
if(arr[i]>='a' && arr[i]<='z'){
dx++;
}else if(arr[i]>='A' && arr[i]<='Z'){
xx++;
}else if(arr[i]>='0' && arr[i]<='9'){
zs++;
}else{
qt++;
}
}
System.out.println("大写字母:"+dx+"\t小写字母:"+xx+"\t整数:"+zs+"\t其他:"+qt);
}
}

如何用java编写一个循环程序?
答:import java.util.*;public class Main { public static void main (String [] args) { Scanner s=new Scanner(System.in);int sum=0;int x=s.nextInt();while(x!=0) { if(x%2==1) { sum+=x;} x=s.nextInt();} System.out.println(sum);} } 运行效果:...

如何用java语言编写一个程序?
答:根据目的判断,需要调取到的函数有randi、mod、mean、find,分别用于产生随机整数、判断是否为偶数、计算平均数、寻找满足条件元素的下标。代码如下:clc;clear;n=randi([10,99],[1,20])%产生随机数,在10到99之间的均匀随机数 a=mean(n)%计算平均数 n(find(n...

java编写一个奶茶点单程序代码怎么写?
答:import java.util.Scanner;public class MilkTeaOrder { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);System.out.println("欢迎来到奶茶店!");System.out.println("请选择您的口味:");System.out.println("1. 原味奶茶");System.out.println("2. 珍珠...

用Java编写一个程序,要求如下:
答:1.内部使用 C 的 longjmp 机制让出一个协程。 因此,如果一个 C 函数 foo 调用了一个 API 函数, 而这个 API 函数让出了(直接或间接调用了让出函数)。 由于 longjmp 会移除 C 栈的栈帧, Lua 就无法返回到 foo 里了。2.为了回避这类问题, 碰到 API 调用中调用让出时,除了那些抛出错误...

Java编写一个程序,在屏幕上打印出如下图形?
答:打印杨辉三角图形的Java程序如下 public class H{ public static void main(String[] args) { int i,j,N=7;int[][] a=new int[N][N];for(i=0;i<N;i++){ a[i][0]=1;a[i][i]=1;} for(i=2;i<N;i++)for(j=1;j<i;j++)a[i][j]=a[i-1][j-1]+a[i-1][j]...

编写java程序
答:java.util.*;public class Test{ public static void main(String[] args){ Scanner scan=new Scanner(System.in); System.out.println("请输入一个整数"); int x=scan.nextInt(); int y=0; if(x<0) y=-1+2*x; else if(x==0) y=-1; else y=-1...

在java中编写程序,定义一个学生类
答:/ 编写一个Java应用程序,该程序包括3个类:定义一个学生类,Student有姓名,学号,选学的课程列表 定义一个课程类:课程名称,课程分数 (1)初始化一个学生,选择了三门课程,并添加到学生的属性中 (2)实现统计学生的总分功能 1.正确编写2个类(5分)2.统计学生的总分功能(5分)/ public class ...

用JAVA编写一个程序,要求如下:
答:import java.util.Scanner;public class StudentTest {public static void main(String[] args) {Student student = new Student();Scanner sc = new Scanner(System.in);System.out.println("请输入姓名:");student.setName(sc.next());System.out.println("请输入性别:");student.setSex(sc....

JAVA编写程序?
答:} };} }class Inner { public static class InnerDemo { public static void main(String[] args) { Outer.method().show();} } } 这个程序中定义了一个接口 Inter 和一个外部类 Outer。Outer 类中有一个静态方法 method,该方法返回了一个实现了 Inter 接口的匿名内部类的实例,实现...

用java写一个程序?
答:以下是一个使用Java语言编写的程序,可以计算出20000000~300000000之间所有的素数,并将找到的素数写入primefile.dat文件:javaCopy code import java.io.FileOutputStream; import java.io.IOException; public class PrimeNumberCalculator { public static void main(String[] args) { int start = 20000000...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网