java代码
* Created by y0n on 2017/4/17.
* 1.输出控制台传递的默认参数
*/
public class JavaDay001_1 {
public static void main(String[] args) {
System.out.println(args);
}
}
/**
* Created by y0n on 2017/4/17.
* 2.编程求表达式的结果
*/
public class JavaDay001_2 {
public static void main(String[] args) {
System.out.println("128 129 = " + (128 129));
System.out.println("56 | 32 = " + (56 | 32));
System.out.println("27 ^ 123 = " + (27 ^ 123));
}
}
/**
* Created by y0n on 2017/4/17.
* 3.从键盘上输入3个数,求出这三个数字中的最大值,并将最大值输出
*/
import java.util.Scanner;
public class JavaDay001_3 {
public static void main(String[] args) {
System.out.println("请输入3个数:");
Scanner scanner = new Scanner(System.in);
int nNumA = scanner.nextInt();
int nNumB = scanner.nextInt();
int nNumC = scanner.nextInt();
int nMax = 0;
if (nNumA = nNumB nNumA = nNumC)
{
nMax = nNumA;
}
else if (nNumB = nNumC nNumB = nNumA)
{
nMax = nNumB;
}
else if (nNumC = nNumA nNumC = nNumB)
{
nMax = nNumC;
}
else
{
System.out.println("无法比较!");
}
System.out.println("Max = " + nMax);
}
}
/**
* Created by y0n on 2017/4/17.
* 4.编写万年历小程序
* 输出结果:
* 请输入年:2016
* 请输入月:6
* 2016年非润年
* 2016年6月份的天数是30
*/
import com.sun.webkit.BackForwardList;
import java.util.Scanner;
public class JavaDay001_4 {
public static void main(String[] args) {
System.out.println("请输入年:");
Scanner scanner = new Scanner(System.in);
int nYear = scanner.nextInt();
System.out.println("请输入月:");
int nMounth = scanner.nextInt();
int nflag = 0;
if (nYear % 4 == 0)
{
if (nYear % 100 == 0)
{
if (nYear % 400 == 0)
{
nflag = 1;
System.out.println(nYear + "年是润年");
}
else
{
System.out.println(nYear + "年不是润年");
}
}
else
{
nflag = 1;
System.out.println(nYear + "年不是润年");
}
}
else
{
System.out.println(nYear + "年不是润年");
}
//判断2016年月份的天数
if (nMounth == 1
|| nMounth == 3
|| nMounth == 5
|| nMounth == 7
|| nMounth == 8
|| nMounth == 10
|| nMounth == 12 )
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:31" );
}
else if (nMounth == 4
|| nMounth == 6
|| nMounth == 9
|| nMounth == 11)
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:30" );
}
辛苦,望采纳!老铁
java练习题求完整代码
按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004","赵六",73.5);
sArray[4]=new Student("005","孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}
给段最简单的java代码 让我新手看一下
最简单的java代码肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!
java练习题求解希望有完整代码
具体的代码如下:
import java.util.HashMap;
public class SearchDemo {
public HashMapInteger,Integer countMap(char[] arr){
HashMap countMap = new HashMapInteger, Integer();
for (int i = 0; i arr.length; i++) {
if(!countMap.containsKey(arr[i])){
countMap.put(arr[i],1);
}else{
int value = (int)countMap.get(arr[i]) + 1;
countMap.put(arr[i],value);
}
}
return countMap;
}
public static void main(String[] args) {
char[] arr={'A','1','R','!','e','','A','5','A','g','#','D'};
int count = new SearchDemo().countMap(arr).get('A');
System.out.println("其中'A'字符的个数是:" + count);
}
}