其他分享
首页 > 其他分享> > 2020.8.9第三十四天

2020.8.9第三十四天

作者:互联网

c++例题用java

例1.1

1 public class cjava {
2 public static void main (String[] args){
3     System.out.println("This is a c++ program");
4 }
5 }

 

 例1.2

 1 import java.util.Scanner;
 2 public class cjava {
 3 public static void main (String[] args){
 4     Scanner con=new Scanner(System.in);
 5     System.out.println("请输入数字a:");
 6     int a=con.nextInt();
 7     System.out.println("请输入数字b:");
 8     int b=con.nextInt();
 9     System.out.println("a+b="+(a+b));
10 }
11 }

 

 例1.3

 1 import java.util.Scanner;
 2 public class cjava {
 3 public static void main (String[] args){
 4     Scanner con=new Scanner(System.in);
 5     System.out.println("请输入数字1:");
 6     int a=con.nextInt();
 7     System.out.println("请输入数字2:");
 8     int b=con.nextInt();
 9     if(a>b)
10     System.out.println("最大值是"+a);
11     else if(b>a)
12     System.out.println("最大值是"+b);    
13     else
14     System.out.println("两数相等");
15 }
16 }

 

 例1.4

import java.util.Scanner;
public class Student{
    int num;
    int score;
    public void setdate() {
        Scanner con=new Scanner(System.in);
        num=con.nextInt();
        score=con.nextInt();
    }
    public void display() {
        System.out.println("学号="+num+",成绩="+score);
    }
};
public class cjava {
public static void main (String[] args){
    Student a =new Student();
    Student b =new Student();
    a.setdate();
    b.setdate();
    a.display();
    b.display();
}
}

 

 2.遇到的问题:忘记如何使用函数

3.明天继续写例题

标签:2020.8,Scanner,第三十四,System,println,con,public,out
来源: https://www.cnblogs.com/Nojava/p/13463700.html