Java编程

牛客网机试题java

閾炬帴锛歨ttps://www.nowcoder.com/questionTerminal/d9aa3894d3aa4887843a85d26daa4437鏉ユ簮锛氱墰瀹㈢綉import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner input = new Scanner(System.in);while (input.hasNext()) {String s = input.nextLine();String r = sort(s);System.out.println(r);}}public static String sort(String s) {if (s.length() <= 0) {return null;}char[] c = s.toCharArray();StringBuffer sb = new StringBuffer();// 瀵瑰瓧姣嶈繘琛屾帓搴忕殑鎬濇兂鏄細灏嗘瘡涓€瀛楃涓?a'-'z'鎴?A'-'Z'鍋氭瘮杈冿紝骞舵坊鍔犲埌瀛楃缂撳啿涓紝缁忚繃姝ゆ楠ゅ畬鎴愪簡// 涓嶅悓瀛楁瘝鎸夐€掑椤哄簭鎺掑簭锛屽悓涓€瀛楁瘝锛堜笉鍖哄垎澶у皬鍐欙級鎸夊師鏉ラ『搴忔帓鍒椼€?/span>for (int i = 0; i < 26; i++) {for (int j = 0; j < c.length; j++) {if (c[j] == 'a' + i。

牛客网机试题java

import java.util.Scanner;public class Test{public static void main(String[] args){Scanner scanner = new Scanner(System.in);System.out.print(“请输入上次考试成绩:”);int grade1 = scanner.nextInt();System.out.print(“请输入本次考试成绩:”);int grade2 = scanner.nextInt();float percent = (float)(grade2 – grade1)/ grade1*100;System.out.printf(“%.2f%%\n”,percent);}}(二)if判断if语句的基本语法是。

StartSMS.javapackage cn.itcast;import java.util.Scanner;/ 系统开启类** @author Administrator**/public class StartSMS {public StartSMS() {}public static void main(String args[]) {Data data = new Data();data.ini();Menu menu = new Menu();menu.setData(data.goodsName, data.goodsPrice, data.custNo,data.custBirth, data.custScore);menu.showLoginMenu();boolean flag = true;label0: do {if (!flag)break;Scanner scanner = new Scanner(System.in);int i = scanner.nextInt();VerifyEqual verifyequal = new VerifyEqual();switch (i) {case 1: // ‘\001’int j = 3;do {if (j < 1)continue label0;if (verifyequal.verify(data.manager.username,data.manager.password)) {menu.showMainMenu();continue label0;}if (j != 1) {System.out.println("\n用户名和密码不匹配,请重新输入:");} else {System.out.println("\n您没有权限进入系统!谢谢!");flag = false;}j--;} while (true);case 2: // '\002'if (verifyequal.verify(data.manager.username,data.manager.password)) {System.out.print("请输入新的用户名:");data.manager.username = scanner.next();System.out.print("请输入新的密码:");data.manager.password = scanner.next();System.out.println("用户名和密码已更改!");System.out.println("\n请选择,输入数字:");} else {System.out.println("抱歉,你没有权限修改!");flag = false;}break;case 3: // '\003'System.out.println("谢谢您的使用!");//flag = false;System.exit(0);break;default:System.out.print("\n输入有误!请重新选择,输入数字: ");break;}} while (flag);}}2 VerifyEqual.javapackage cn.itcast;import java.util.Scanner;/ 验证管理员登录** @author Administrator**/public class VerifyEqual {public VerifyEqual() {}public boolean verify(String s, String s1) {System.out.print("请输入用户名:");Scanner scanner = new Scanner(System.in);String s2 = scanner.next();System.out.print("请输入密码:");scanner = new Scanner(System.in);String s3 = scanner.next();return s2.equals(s) && s1.equals(s3);}}3 CustManagement.javapackage cn.itcast;import java.util.Scanner;public class CustManagement {public CustManagement() {}public void setData(String as[], double ad[], int ai[], String as1[],int ai1[]) {goodsName = as;goodsPrice = ad;custNo = ai;custBirth = as1;custScore = ai1;}public void returnLastMenu() {System.out.print("\n\n请按'n'返回上一级菜单:");Scanner scanner = new Scanner(System.in);boolean flag = true;doif (scanner.next().equals("n")) {Menu menu = new Menu();menu.setData(goodsName, goodsPrice, custNo, custBirth,custScore);menu.showCustMMenu();} else {System.out.print("输入错误, 请重新'n'返回上一级菜单:");flag = false;}while (!flag);}public void add() {System.out.println("购物管理系统 > 客户信息管理 > 添加客户信息\n\n”);Scanner scanner = new Scanner(System.in);System.out.print(“请输入会员号(<4位整数>):”);int i = scanner.nextInt();System.out.print(“请输入会员生日(月/日<用两位数表示>):”);String s = scanner.next();System.out.print(“请输入积分:”);int j = scanner.nextInt();int k = -1;int l = 0;do {if (l >= custNo.length)break;if (custNo[l] == 0) {k = l;break;}l++;} while (true);custNo[k] = i;custBirth[k] = s;custScore[k] = j;System.out.println(“新会员添加成功!”);returnLastMenu();}public void modify() {System.out.println(“购物管理系统 > 客户信息管理 > 修改客户信息\n\n”);System.out.print(“请输入会员号:”);Scanner scanner = new Scanner(System.in);int i = scanner.nextInt();System.out.println(” 会员号 生日 积分 “);System.out.println(“————。

答:首先,在你的程序中每个java文件有且只能有一个public类,这个类的类名必须和文件名的大小写完全一样。其次,在你要运行的类中有且只能有一个public static void main(String[] args)方法,这个方法就是你的主程序。

import java.util.Scanner;public class TriangleArea {public static void main(String[] args) {//输入底和高,计算三角形面积System.out.println(“请输入三角形的底和高:”);Scanner sc=new Scanner(System.in);double s=sc.nextDouble();//底double h=sc.nextDouble();//高double triangleArea=area(s,h);System.out.println(“三角形面积为:”+triangleArea);}public static double area(double a,double b) {return a*b*0.5;}}。

public static void main(String[] args) throws ClientProtocolException, IOException {。

学习方式是跟着视频来学,现在还记得那个Java教学的老师是马士兵,配置好环境后,学了浮点数整数等基本概念,还记得一开始代码总是要写什么 public static void,然后就没有然后了,Java就一直呆在硬盘里,一个学期过去了。

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注