又是今天Java实验课做的,这次我好好学习了[aru_13]
第一个程序
从键盘输入一个字符,打印出该字符和对应的ASCII码。直接粘贴程序吧,目前我水平就这样,将就着看吧。
//第一种方法
import java.io.IOException;
public class asii {
public static void main (String args[]) throws IOException
{
System.out.println("请输入要转换ASIIC的字符");
char m=(char)System.in.read();
System.out.println(m+"\t"+(int)m);
}
} //第二种方法,我感觉这两个方法差不多
import java.io.IOException;
public class asii {
public static void main (String args[]) throws IOException
{
System.out.println("请输入要转换ASIIC的字符");
char m=(char)System.in.read();
int c=m;
System.out.println((char)c+"\t"+c);
}
}
第二个程序
打印大写字母和小写字母及ASCII码
//第一种while循环的
public class asii {
public static void main (String args[])
{
System.out.println("大写字母"+"\t"+"ASCII码"+"小写字母"+"\t"+"ASCII码");
int a=64,b=0;
while(a>=64 && a<90)
{
a++;
b=a+32;
System.out.println((char)a+"\t"+a+"\t"+(char)b+"\t"+b+"\t");
}
}
}
//第二种for循环的
public class asii {
public static void main (String args[])
{
System.out.println("大写字母"+"\t"+"ASCII"+"小写字母"+"\t"+"ASCII码");
int a,b=0;
for(a=65;a<90;a++)
{
b=a+32;
System.out.println((char)a+"\t"+a+"\t"+(char)b+"\t"+b+"\t");
}
}
} 第三个程序
键盘输入一个成绩,判断“不及格、几个、中等、良好、优秀”,如果数据输入在<0或>100则打印出“数据输入不合法!”
先贴我第一次写的吧,不对,没有考虑到最后一个大于100和小于0的
import java.io.IOException;
public class asii {
public static void main (String args[]) throws IOException
{
System.out.println("请输入一个成绩");
char a=(char)System.in.read();
char b=(char)System.in.read();
int score=(a-'0')*10+b-'0';
if(score<60)
System.out.println("不及格");
else if(score>=60 && score<70)
System.out.println("及格");
else if(score>=70 && score<80)
System.out.println("中等");
else if(score>=80 && score<90)
System.out.println("良好");
else if(score>=90 && score<=100)
System.out.println("优秀");
else
System.out.println("数据输入不合法!");
}
}
//第二种方法正确
import java.util.Scanner;
public class asii {
public static void main (String args[])
{
double h;
System.out.println("请输入一个成绩");
Scanner s=new Scanner(System.in);
h=s.nextDouble();
if(h<60 && h>=0)
System.out.println("不及格");
else if(h>=60 && h<70)
System.out.println("及格");
else if(h>=70 && h<80)
System.out.println("中等");
else if(h>=80 && h<90)
System.out.println("良好");
else if(h>=90 && h<=100)
System.out.println("优秀");
else
System.out.println("数据输入不合法!");
}
}
ps:就这些吧,欢迎补充。[aru_22]
本文作者为一木,转载请注明。