从昨天起开始学习java 从此坚定信念一条道走到黑
昨天讲了一些java的历史和基础知识 没啥好说的 要点:1.JDK的安装 环境变量的设置 2.快捷键alt+/ (main sysout)
今天上机练习
这两天写的代码
/**import java.util.Scanner;
public class lianxi {
public static void main(String[] args) {
System.out.println("请输入第一个数字:");
Scanner yi = new Scanner(System.in);
int a = yi.nextInt();
System.out.println("请输入运算符:");
Scanner yun = new Scanner(System.in);
String b = yun.next();
System.out.println("请输入第二个数字");
Scanner er = new Scanner(System.in);
int c = er.nextInt();
if (b.equals("+")) {
a += c;
System.out.println(a);
} else if (b.equals("-")) {
a -= c;
System.out.println(a);
} else if (b.equals("*")) {
a *= c;
System.out.println(a);
} else if (b.equals("/")) {
a /= c;
System.out.println(a);
}
}
}
*/
/**import java.util.Scanner;
public class lianxi {
public static void main(String args[])
{
System.out.println("请输入数字:");
Scanner yi = new Scanner(System.in);
int a = yi.nextInt();
System.out.println("请输入运算符:");
Scanner fu = new Scanner(System.in);
String b = fu.next();
System.out.println("请输入数字:");
Scanner er = new Scanner(System.in);
int c = er.nextInt();
if (b.equals("+"))
a += c;
else if (b.equals("-"))
a -= c;
else if (b.equals("*"))
a *= c;
else if (b.equals("/"))
a /= c;
System.out.println(a);
}
}*/
/**import java.util.Scanner;
public class lianxi {
public static void main(String args[]) {
System.out.println("输入:");
Scanner yi = new Scanner(System.in);
int a = yi.nextInt();
System.out.println("符号:");
String b = yi.next();
System.out.println("输入:");
int c = yi.nextInt();
if (b.equals("+"))
a += c;
else if (b.equals("-"))
a -= c;
else if (b.equals("*"))
a *= c;
else if (b.equals("/"))
a /= c;
System.out.println(a);
}
}*/
import java.util.Scanner;
public class lianxi {
public static void main(String args[]){
System.out.println("输入");
Scanner shuru=new Scanner(System.in);
int a=shuru.nextInt();
String b=shuru.next();
int c=shuru.nextInt();
if (b.equals("+"))
a+=c;
else if (b.equals("-"))
a-=c;
else if (b.equals("*"))
a*=c;
else if (b.equals("/"))
a/=c;
System.out.println(a);
}
}
import java.util.Scanner;
public class xunhuan {
public static void main(String[] args) {
/**
* boolean x=true; boolean y=false; System.out.println(x&y);
* System.out.println(x|y); System.out.println(x^y);
* System.out.println(x&&y); System.out.println(x||y); //逻辑运算符运算 int
* b=~3; System.out.println(b);
*
* int salary; String type; type="工人";
* salary=type.equals("经理")?3000:2000;
* System.out.println("我们的薪水是"+salary); //三元运算符 Scanner scan=new
* Scanner(System.in); System.out.println("请输入一个数字"); int
* in=scan.nextInt(); if(in%2==0) System.out.println(in+"是个偶数"); else
* System.out.println(in+"是个奇数"); //流程控制 for
*
* switch (in) { case 200: System.out.println("良好"); break; case 100:
* System.out.println("优秀"); break; default: System.out.println("较差"); }
* //流程控制 switch int i=1; do { in++; i++; } while (i<=100);
* System.out.println(in); //do循环
*
* while (i<=100) { in++; i++; } System.out.println(in); //while循环 int
* k; for( k=1;k<=10;k++) { System.out.println(in); in=in*k; }
* System.out.println(in); System.out.println(k); //for循环
*/
System.out.println("请输入第一个数字:");
Scanner shu = new Scanner(System.in);
int down = shu.nextInt();
System.out.println("请输入运算符:");
Scanner ru = new Scanner(System.in);
String a = ru.next();
System.out.println("请输入第二个数字:");
Scanner er = new Scanner(System.in);
int go = er.nextInt();
if (a.equals("+"))
{
down += go;
System.out.println(down);
}
else if (a.equals("-")) {
down= down-go;
System.out.println(down);
}
else if (a.equals("*")) {
down =down*go;
System.out.println(down);
}
else if (a.equals("/")) {
down /= go;
System.out.println(down);
}
}
}
呵呵 挺幼稚的程序 今天的收获是掌握了如何接收从外部输入的数据并存储 import java. until.Scanner; Scanner ver=new Scanner(System.in);
int a=ver.nextInt();